Commit 3d55d31
authored
proxy: replace http.Error with httputil.WriteErrorResponse for consistent JSON error shape (#5819)
`internal/proxy/handler.go` mixed `http.Error` (plain-text `text/plain`
responses) with `httputil.WriteErrorResponse`/`WriteJSONResponse`
(JSON), breaking client-side error handling. The `httputil` package
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 7 `http.Error` calls with
`httputil.WriteErrorResponse`, assigning appropriate error codes:
| HTTP status | error code |
|---|---|
| 400 Bad Request | `bad_request` |
| 403 Forbidden | `forbidden` |
| 502 Bad Gateway | `bad_gateway` |
| 503 Service Unavailable | `service_unavailable` |
| 500 Internal Server Error | `internal_error` |
```go
// Before — plain text, inconsistent Content-Type
http.Error(w, "upstream request failed", http.StatusBadGateway)
// After — uniform JSON shape across all error paths
httputil.WriteErrorResponse(w, http.StatusBadGateway, "bad_gateway", "upstream request failed")
```2 files changed
Lines changed: 25 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
169 | | - | |
| 169 | + | |
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
| 335 | + | |
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| |||
401 | 401 | | |
402 | 402 | | |
403 | 403 | | |
404 | | - | |
| 404 | + | |
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
410 | | - | |
| 410 | + | |
411 | 411 | | |
412 | 412 | | |
413 | 413 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
51 | 67 | | |
52 | 68 | | |
53 | 69 | | |
| |||
112 | 128 | | |
113 | 129 | | |
114 | 130 | | |
115 | | - | |
116 | | - | |
| 131 | + | |
117 | 132 | | |
118 | 133 | | |
119 | 134 | | |
| |||
456 | 471 | | |
457 | 472 | | |
458 | 473 | | |
459 | | - | |
| 474 | + | |
460 | 475 | | |
461 | 476 | | |
462 | 477 | | |
| |||
0 commit comments