Skip to content

fix(sdk): avoid raw SyntaxError on non-JSON error responses#2102

Open
mitre88 wants to merge 1 commit intoupstash:masterfrom
mitre88:fix/1964-httpclient-non-json-error
Open

fix(sdk): avoid raw SyntaxError on non-JSON error responses#2102
mitre88 wants to merge 1 commit intoupstash:masterfrom
mitre88:fix/1964-httpclient-non-json-error

Conversation

@mitre88
Copy link

@mitre88 mitre88 commented Mar 4, 2026

Summary

  • wrap SDK error JSON parsing in a safe try/catch path inside HttpClient.request()
  • ensure non-JSON error bodies still produce a typed Context7Error
  • add unit tests for JSON and non-JSON error response behavior

Why

When the API returns HTML/plain-text error content, res.json() throws a raw SyntaxError. This bypasses Context7Error handling in consumers.

Verification

  • pnpm --filter @upstash/context7-sdk lint
  • pnpm --filter @upstash/context7-sdk exec vitest run src/http/index.test.ts

Closes #1964

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: SDK HttpClient throws raw SyntaxError instead of Context7Error on non-JSON error responses

1 participant