checkAPIResponse checks an API response for permission or general errors. Returns nil if the response is OK, or a structured error otherwise.
(resp *apiResponse, operation, permission string)
| 559 | // checkAPIResponse checks an API response for permission or general errors. |
| 560 | // Returns nil if the response is OK, or a structured error otherwise. |
| 561 | func checkAPIResponse(resp *apiResponse, operation, permission string) error { |
| 562 | if resp.Status == http.StatusForbidden || resp.Status == http.StatusUnauthorized { |
| 563 | return &toolError{ |
| 564 | Code: "PERMISSION_DENIED", |
| 565 | Message: fmt.Sprintf("you don't have permission to %s", operation), |
| 566 | Suggestion: fmt.Sprintf("ask your workspace admin to grant you the %s permission", permission), |
| 567 | } |
| 568 | } |
| 569 | if resp.Status >= 400 { |
| 570 | return errors.Errorf("%s failed: HTTP %d: %s", operation, resp.Status, parseError(resp.Body)) |
| 571 | } |
| 572 | return nil |
| 573 | } |
| 574 | |
| 575 | // formatChangeError formats a changeError into an MCP error result. |
| 576 | func formatChangeError(err *changeError) *mcp.CallToolResult { |
no test coverage detected