Skip to content

bug: response.json() can throw unhandled SyntaxError #4

@satoshai-dev

Description

@satoshai-dev

Description

If the Stacks API returns a 200 with a non-JSON body (corrupted response, gateway HTML error page), response.json() will throw an unhandled SyntaxError. The error message gives no indication of what went wrong.

Location

src/fetcher.ts:47return (await response.json()) as ClarityAbi;

Suggested fix

Wrap in try/catch and re-throw with context:

try {
  return (await response.json()) as ClarityAbi;
} catch (cause) {
  throw new Error(
    `Invalid JSON response for ${address}.${name} on ${network}`,
    { cause },
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions