Skip to content

Commit

Permalink
Fix error handling in dust-client (#8588)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraggle authored Nov 12, 2024
1 parent 3b4ec2a commit cca5b05
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sdks/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,12 +958,13 @@ export class DustAPI {
const text = await res.value.response.text();

try {
const r = schema.safeParse(JSON.parse(text));
const response = JSON.parse(text);
const r = schema.safeParse(response);
if (r.success) {
return new Ok(r.data as z.infer<T>);
} else {
// We couldn't parse the response directly, maybe it's an error
const rErr = APIErrorSchema.safeParse(JSON.parse(text));
const rErr = APIErrorSchema.safeParse(response["error"]);
if (rErr.success) {
// Successfully parsed an error
return new Err(rErr.data);
Expand Down

0 comments on commit cca5b05

Please sign in to comment.