writeUpstreamError marshals and writes a given error.
(w http.ResponseWriter, antErr *responseError)
| 406 | |
| 407 | // writeUpstreamError marshals and writes a given error. |
| 408 | func (i *interceptionBase) writeUpstreamError(w http.ResponseWriter, antErr *responseError) { |
| 409 | if antErr == nil { |
| 410 | return |
| 411 | } |
| 412 | |
| 413 | w.Header().Set("Content-Type", "application/json") |
| 414 | w.WriteHeader(antErr.StatusCode) |
| 415 | |
| 416 | out, err := json.Marshal(antErr) |
| 417 | if err != nil { |
| 418 | i.logger.Warn(context.Background(), "failed to marshal upstream error", slog.Error(err), slog.F("error_payload", fmt.Sprintf("%+v", antErr))) |
| 419 | // Response has to match expected format. |
| 420 | // See https://docs.claude.com/en/api/errors#error-shapes. |
| 421 | _, _ = w.Write([]byte(fmt.Sprintf(`{ |
| 422 | "type":"error", |
| 423 | "error": { |
| 424 | "type": "error", |
| 425 | "message":"error marshaling upstream error" |
| 426 | }, |
| 427 | "request_id": "%s" |
| 428 | }`, i.ID().String()))) |
| 429 | } else { |
| 430 | _, _ = w.Write(out) |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | func (i *interceptionBase) hasInjectableTools() bool { |
| 435 | return i.mcpProxy != nil && len(i.mcpProxy.ListTools()) > 0 |
no test coverage detected