MCPcopy Create free account
hub / github.com/coder/coder / writeErrorResponse

Function writeErrorResponse

coderd/x/chatd/chattest/errors.go:19–31  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

17// writeErrorResponse writes a JSON error response matching the common
18// provider error format used by both Anthropic and OpenAI.
19func 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.

Callers 4

writeResponseMethod · 0.85
handleResponsesMethod · 0.85

Calls 5

EncodeMethod · 0.80
SetMethod · 0.65
HeaderMethod · 0.45
WriteHeaderMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected