Skip to content

fix(client): Handle empty JSON responses#1159

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/handle-empty-json-response
Open

fix(client): Handle empty JSON responses#1159
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/handle-empty-json-response

Conversation

@sentry

@sentry sentry Bot commented Jul 15, 2026

Copy link
Copy Markdown

This PR addresses the issue "Error: Failed to parse JSON response: Unexpected end of JSON input" occurring in SentryApiService.parseJsonResponse.

Root Cause:
The parseJsonResponse method in packages/mcp-core/src/api-client/client.ts directly calls response.json() without checking if the response body is empty. This leads to an Unexpected end of JSON input error when Sentry API endpoints return a 200 or 204 status with no content, or when Cloudflare's fetch layer delivers an empty body.

Solution:
Modified parseJsonResponse to first read the response body as text. If the trimmed text content is empty, it now returns null, effectively bypassing the JSON parsing attempt for empty responses. For non-empty responses, it proceeds to parse the text as JSON within the existing error handling block. This prevents the parsing error while maintaining correct behavior for valid JSON and appropriate error reporting for malformed non-empty responses.

Fixes MCP-SERVER-FY2

Comment @sentry <feedback> on this PR to have Autofix iterate on the changes.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d9aff4a. Configure here.

const text = await response.text();
if (text.trim() === "") {
return null;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null return breaks caller contracts

Medium Severity

parseJsonResponse now returns null for empty bodies, but every requestJSON caller still treats the result as required response data. Untyped call sites cast and read fields immediately, so empty responses become TypeErrors instead of the previous parse failure. Zod-backed call sites fail later with schema errors. Endpoints that intentionally return no body already go through request, not requestJSON.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d9aff4a. Configure here.

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.

0 participants