proxy: replace http.Error with httputil.WriteErrorResponse for consistent JSON error shape#5819
Merged
Merged
Conversation
5 tasks
Copilot
AI
changed the title
[WIP] Fix inconsistent HTTP error response format in handler.go
proxy: replace http.Error with httputil.WriteErrorResponse for consistent JSON error shape
May 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR standardizes error responses emitted by the proxy handler so clients consistently receive JSON error bodies (via internal/httputil.WriteErrorResponse) instead of a mix of JSON and text/plain from http.Error, aligning proxy error behavior with the rest of the gateway.
Changes:
- Replaced 7
http.Errorcall sites ininternal/proxy/handler.gowithhttputil.WriteErrorResponse. - Normalized status-to-error-code mappings for common proxy failure paths (400/403/500/502/503).
Show a summary per file
| File | Description |
|---|---|
| internal/proxy/handler.go | Switches all remaining plain-text http.Error responses to httputil.WriteErrorResponse to ensure a consistent JSON error shape. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Comment on lines
+83
to
85
| httputil.WriteErrorResponse(w, http.StatusBadRequest, "bad_request", "failed to read request body") | ||
| return | ||
| } |
Collaborator
|
@copilot address review feedback |
Contributor
Author
This was referenced May 16, 2026
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.
internal/proxy/handler.gomixedhttp.Error(plain-texttext/plainresponses) withhttputil.WriteErrorResponse/WriteJSONResponse(JSON), breaking client-side error handling. Thehttputilpackage explicitly documents that both server and proxy packages must use these helpers so API consumers always receive the same{"error":"...","message":"..."}shape.Changes
internal/proxy/handler.go: Replace all 7http.Errorcalls withhttputil.WriteErrorResponse, assigning appropriate error codes:bad_requestforbiddenbad_gatewayservice_unavailableinternal_error