fix(http-client): throw on non-2xx responses so MCP tools surface errors correctly#70
Open
fuleinist wants to merge 1 commit into
Open
fix(http-client): throw on non-2xx responses so MCP tools surface errors correctly#70fuleinist wants to merge 1 commit into
fuleinist wants to merge 1 commit into
Conversation
…ors correctly Fixes 21st-dev#66 Before: response.ok was never checked, so server errors (500, 503, etc.) returned as successful tool results with the error text as the output. Example: /api/refine-ui returning 'Anthropic experiencing high load' as HTTP 200 would appear as a successful refinement to the MCP client. After: createMethod now throws an Error with the HTTP status and server error body when response.ok is false. MCP clients receive a proper error they can surface to the user. Added 3 regression tests covering: - 500 with JSON error body - 503 with no body - 401 with JSON error body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #66
Before:
response.okwas never checked, so server errors (500, 503, etc.) returned as successful tool results with the error text as the output. Example:/api/refine-uireturning "Anthropic experiencing high load" as HTTP 200 would appear as a successful refinement to the MCP client — the client could not distinguish an outage from a real refinement.After:
createMethodnow throws anErrorwith the HTTP status and server error body whenresponse.okis false. MCP clients receive a proper error they can surface to the user.Changes
fetch(), checkresponse.ok. If false, read the response body as text and throwError(HTTP {status} {statusText}: {errorText}). If the body can't be read, fall back to just the status text.Test results