parseError extracts the error message from an API error response body.
(body json.RawMessage)
| 67 | |
| 68 | // parseError extracts the error message from an API error response body. |
| 69 | func parseError(body json.RawMessage) string { |
| 70 | var errMap map[string]any |
| 71 | if json.Unmarshal(body, &errMap) != nil { |
| 72 | return "" |
| 73 | } |
| 74 | if msg, ok := errMap["message"].(string); ok { |
| 75 | return msg |
| 76 | } |
| 77 | if code, ok := errMap["code"].(string); ok { |
| 78 | return code |
| 79 | } |
| 80 | return "" |
| 81 | } |
| 82 | |
| 83 | // toolError is a structured error returned by MCP tools. |
| 84 | type toolError struct { |