Skip to content

fix(sdk/go): return structured APIError instead of flattening error response (closes #436)#442

Open
yw13931835525-cyber wants to merge 1 commit intoAgent-Field:mainfrom
yw13931835525-cyber:fix/436-sdk-error-struct
Open

fix(sdk/go): return structured APIError instead of flattening error response (closes #436)#442
yw13931835525-cyber wants to merge 1 commit intoAgent-Field:mainfrom
yw13931835525-cyber:fix/436-sdk-error-struct

Conversation

@yw13931835525-cyber
Copy link
Copy Markdown

详见文件

…esponse

Issue Agent-Field#436: AI client flattens structured error responses into fmt.Errorf,
losing HTTP status code, error type, and error code — preventing callers
from distinguishing auth (401) vs rate-limit (429) vs server errors (5xx).

Changes:
- Add APIError struct with HTTPStatus, Type, Code, Message fields
- Implement error interface with IsRetryable(), IsAuthError(), IsRateLimited()
- Update doRequest (both streaming and non-streaming) to return *APIError
- Callers can now use type assertion to access structured error fields

Fixes Agent-Field#436
@yw13931835525-cyber yw13931835525-cyber requested review from a team and AbirAbbas as code owners April 12, 2026 03:29
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


由伟 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@santoshkumarradha
Copy link
Copy Markdown
Member

santoshkumarradha commented Apr 12, 2026

Appreciate the contribution here. There are two things to address before this can move forward: first, the CLA assistant check above, including linking the commit author email to your GitHub account; and second, the code changes requested in the review below. Please sort out the CLA/email mismatch, rerun the check, and then take a look at the requested-changes review for the API error handling updates still needed.

Copy link
Copy Markdown
Member

@santoshkumarradha santoshkumarradha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on. I am requesting changes before this can move ahead. The intent is good, but this does not fully satisfy #436 yet: the issue asks for a structured API error that also preserves the raw response body when parsing fails, and tests for the new behavior. As written, non-JSON error responses in the streaming path can lose the useful raw error text entirely, which is a regression for callers trying to debug upstream failures. Please add the raw-body fallback and the corresponding tests before we move this forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants