Extract error messages from AI service error responses#239
Conversation
Read and display the actual error message from the server's JSON response instead of showing a generic "server returned status N" message. This improves UX when hitting quota limits or other server-side errors. https://claude.ai/code/session_01MBUEGHLc7PNCCemm4Cddnt
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Summary of ChangesHello @AnnatarHe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the AI service's error reporting by enabling the extraction of specific error messages from API responses. This change provides users with more actionable and descriptive error feedback, moving beyond generic HTTP status codes, and ensures the system gracefully handles various error conditions through robust testing. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
The pull request introduces improved error handling for the AI service by extracting detailed error messages from API error responses. This change enhances user feedback by providing more specific error information instead of generic HTTP status codes. The implementation correctly falls back to a generic message if the response body cannot be parsed or contains an empty error message. Comprehensive test coverage has been added to validate various error scenarios, including quota exceeded, unauthorized, service unavailable, non-JSON responses, and empty error messages. The changes are well-implemented and tested, significantly improving the robustness of the AI service's error reporting.
| body, readErr := io.ReadAll(resp.Body) | ||
| if readErr == nil { | ||
| var errResp errorResponse | ||
| if jsonErr := json.Unmarshal(body, &errResp); jsonErr == nil && errResp.ErrorMessage != "" { | ||
| return fmt.Errorf("%s", errResp.ErrorMessage) | ||
| } | ||
| } |
There was a problem hiding this comment.
The errorResponse struct is used here but not defined in ai_service.go. It should be defined in model/ai_service.go or imported from model/api.base.go if it's a common type. Defining it directly in ai_service.go would make this file self-contained for its error handling logic.
body, readErr := io.ReadAll(resp.Body)
if readErr == nil {
type errorResponse struct {
ErrorCode int `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
var errResp errorResponse
if jsonErr := json.Unmarshal(body, &errResp); jsonErr == nil && errResp.ErrorMessage != "" {
return fmt.Errorf("%s", errResp.ErrorMessage)
}
}
Summary
Improved error handling in the AI service to extract and return detailed error messages from API error responses, providing better feedback to users instead of generic HTTP status codes.
Key Changes
QueryCommandStreaminai_service.goto parse error response bodies and extract theErrorMessagefield when the API returns a non-200 status codeai_service_test.gowith test cases for:Implementation Details
ErrorMessagefield is non-empty, that message is returned to the callerhttps://claude.ai/code/session_01MBUEGHLc7PNCCemm4Cddnt