Skip to content

Commit

Permalink
Include substrate-request-id in non-200 errors to help users diagnose (
Browse files Browse the repository at this point in the history
…#86)

* Include substrate-request-id in non-200 errors to help users diagnose

* Format code
  • Loading branch information
liamgriffiths authored Jun 18, 2024
1 parent eb59624 commit 8a1ac87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 14 additions & 4 deletions examples/implicit-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ async function main() {
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });

const a = new GenerateText(
{ prompt: "tell me about windmills" },
{ prompt: "tell me about windmills", max_tokens: 10 },
{ id: "a" },
);
const b = new GenerateText({ prompt: a.future.text }, { id: "b" });
const c = new GenerateText({ prompt: b.future.text }, { id: "c" });
const b = new GenerateText(
{ prompt: a.future.text, max_tokens: 10 },
{ id: "b" },
);
const c = new GenerateText(
{ prompt: b.future.text, max_tokens: 10 },
{ id: "c" },
);
const d = new GenerateText(
{ prompt: c.future.text, max_tokens: 10 },
{ id: "d" },
);

// Because the `c` is the the final node in the graph we can find nodes it depends
// on through the relationships created via the input arguments.
const res = await substrate.run(c);
const res = await substrate.run(d);
console.log(res.json);
}
main();
3 changes: 2 additions & 1 deletion src/Substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ export class Substrate {

return res;
} else {
const requestId = request.headers.get("x-substrate-request-id");
throw new SubstrateError(
`Request failed: ${apiResponse.status} ${apiResponse.statusText}`,
`[Request failed] status=${apiResponse.status} statusText=${apiResponse.statusText} requestId=${requestId}`,
);
}
} catch (err: unknown) {
Expand Down

0 comments on commit 8a1ac87

Please sign in to comment.