Consolidate proxy rejection handling in handler.go for consistent logging/tracing/error responses - #9251
Merged
Merged
Conversation
7 tasks
Copilot
AI
changed the title
[WIP] Refactor duplicate error handling in proxy/handler.go
Consolidate proxy rejection handling in Jul 13, 2026
handler.go for consistent logging/tracing/error responses
lpcox
marked this pull request as ready for review
July 13, 2026 14:01
Contributor
There was a problem hiding this comment.
Pull request overview
Centralizes proxy rejection handling to standardize error logging, tracing, and JSON responses.
Changes:
- Adds
rejectProxyRequest. - Migrates six proxy failure paths.
- Adds focused helper regression coverage.
Show a summary per file
| File | Description |
|---|---|
internal/proxy/handler.go |
Consolidates proxy rejection handling. |
internal/proxy/handler_test.go |
Tests nil-safe standardized responses. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 4
- Review effort level: Medium
Comment on lines
+38
to
+41
| logger.LogError("proxy", "Request rejected: status=%d code=%s message=%s err=%v", status, code, msg, err) | ||
| if err == nil { | ||
| err = errors.New(msg) | ||
| } |
| if err != nil { | ||
| logHandler.Printf("forwardAndReadBody: upstream request failed: method=%s path=%s err=%v", method, path, err) | ||
| httputil.WriteErrorResponse(w, http.StatusBadGateway, "bad_gateway", "upstream request failed") | ||
| rejectProxyRequest(w, span, http.StatusBadGateway, "bad_gateway", "upstream request failed", err) |
| if err != nil { | ||
| logHandler.Printf("forwardAndReadBody: body read failed: method=%s path=%s status=%d err=%v", method, path, resp.StatusCode, err) | ||
| httputil.WriteErrorResponse(w, http.StatusBadGateway, "bad_gateway", "failed to read upstream response") | ||
| rejectProxyRequest(w, span, http.StatusBadGateway, "bad_gateway", "failed to read upstream response", err) |
| if err != nil { | ||
| logHandler.Printf("forwardAndReadBody: upstream request failed: method=%s path=%s err=%v", method, path, err) | ||
| httputil.WriteErrorResponse(w, http.StatusBadGateway, "bad_gateway", "upstream request failed") | ||
| rejectProxyRequest(w, span, http.StatusBadGateway, "bad_gateway", "upstream request failed", err) |
Collaborator
|
@copilot address review feedback |
…, fix double span recording, add request context to error wrapping
Contributor
Author
Done in commit addressing all four review points:
|
This was referenced Jul 13, 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.gohad repeated inline rejection logic (log + span error + JSON error response) across multiple branches, with inconsistent observability behavior between paths. This change centralizes that pattern so proxy failures are handled uniformly and easier to maintain.Centralized rejection path
rejectProxyRequest(...)to encapsulate:logger.LogError)tracing.RecordSpanError, when span is present)httputil.WriteErrorResponse)Replaced duplicated inline error blocks
Focused regression coverage
TestRejectProxyRequestto validate helper output shape and nil-safe behavior.