MCPcopy Create free account
hub / github.com/coder/aibridge / writeUpstreamError

Method writeUpstreamError

intercept/messages/base.go:408–432  ·  view source on GitHub ↗

writeUpstreamError marshals and writes a given error.

(w http.ResponseWriter, antErr *responseError)

Source from the content-addressed store, hash-verified

406
407// writeUpstreamError marshals and writes a given error.
408func (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
434func (i *interceptionBase) hasInjectableTools() bool {
435 return i.mcpProxy != nil && len(i.mcpProxy.ListTools()) > 0

Callers 2

ProcessRequestMethod · 0.45
ProcessRequestMethod · 0.45

Calls 5

IDMethod · 0.95
HeaderMethod · 0.80
WriteHeaderMethod · 0.45
ErrorMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected