writeErrorResponse writes a JSON error response matching the common provider error format used by both Anthropic and OpenAI.
(t testing.TB, w http.ResponseWriter, errResp *ErrorResponse)
| 17 | // writeErrorResponse writes a JSON error response matching the common |
| 18 | // provider error format used by both Anthropic and OpenAI. |
| 19 | func writeErrorResponse(t testing.TB, w http.ResponseWriter, errResp *ErrorResponse) { |
| 20 | w.Header().Set("Content-Type", "application/json") |
| 21 | w.WriteHeader(errResp.StatusCode) |
| 22 | body := map[string]interface{}{ |
| 23 | "error": map[string]interface{}{ |
| 24 | "type": errResp.Type, |
| 25 | "message": errResp.Message, |
| 26 | }, |
| 27 | } |
| 28 | if err := json.NewEncoder(w).Encode(body); err != nil { |
| 29 | t.Errorf("writeErrorResponse: failed to encode error response: %v", err) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // AnthropicErrorResponse returns an AnthropicResponse that causes the |
| 34 | // test server to respond with the given HTTP status code and error. |
no test coverage detected