writeUpstreamError marshals and writes a given error.
(w http.ResponseWriter, oaiErr *responseError)
| 175 | |
| 176 | // writeUpstreamError marshals and writes a given error. |
| 177 | func (i *interceptionBase) writeUpstreamError(w http.ResponseWriter, oaiErr *responseError) { |
| 178 | if oaiErr == nil { |
| 179 | return |
| 180 | } |
| 181 | |
| 182 | w.Header().Set("Content-Type", "application/json") |
| 183 | w.WriteHeader(oaiErr.StatusCode) |
| 184 | |
| 185 | out, err := json.Marshal(oaiErr) |
| 186 | if err != nil { |
| 187 | i.logger.Warn(context.Background(), "failed to marshal upstream error", slog.Error(err), slog.F("error_payload", fmt.Sprintf("%+v", oaiErr))) |
| 188 | // Response has to match expected format. |
| 189 | _, _ = w.Write([]byte(`{ |
| 190 | "error": { |
| 191 | "type": "error", |
| 192 | "message":"error marshaling upstream error", |
| 193 | "code": "server_error" |
| 194 | }, |
| 195 | }`)) |
| 196 | } else { |
| 197 | _, _ = w.Write(out) |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | func (i *interceptionBase) hasInjectableTools() bool { |
| 202 | return i.mcpProxy != nil && len(i.mcpProxy.ListTools()) > 0 |
no test coverage detected