-
Notifications
You must be signed in to change notification settings - Fork 64
fix: align error handling with OpenCode plugin conventions (#80) #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: align error handling with OpenCode plugin conventions (#80) #81
Conversation
- Token refresh failures now throw errors instead of returning Response - API error responses returned as-is for OpenCode/AI SDK to handle - Matches pattern used by opencode-copilot-auth and opencode-anthropic-auth Fixes numman-ali#80
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors error handling to align with OpenCode plugin conventions, ensuring errors are properly displayed in the UI. The key changes involve making token refresh failures throw errors instead of returning Response objects, and returning API error responses as-is for the OpenCode/AI SDK to handle.
Key Changes
- Token refresh failures now throw
Errorinstead of returning{ success: false, response }objects - API error responses are returned unchanged (using
response.clone()for logging) instead of enriching them with additional fields - Simplified error handling in the main fetch function by letting errors propagate naturally
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/request/fetch-helpers.ts | Updated refreshAndUpdateToken() to throw on failure; modified handleErrorResponse() to return original response using clone; removed unused HTTP_STATUS import and toNumber() helper |
| index.ts | Simplified token refresh call by removing error check logic (errors propagate via throw) |
| test/fetch-helpers.test.ts | Updated test to verify original response is preserved instead of checking for enriched error fields |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c70213f to
80e1c0d
Compare
|
Added tests for The tests cover:
|
|
Accidentally closed it when I just wanted to rename it. Reopened. |
Summary
opencode-copilot-authandopencode-anthropic-authProblem
The plugin's error handling didn't follow OpenCode plugin conventions, causing errors to display incorrectly in the UI (persisting errors, raw JSON output).
Changes
lib/request/fetch-helpers.tsrefreshAndUpdateToken(): Now throwsErroron failure instead of returning{ success: false, response }handleErrorResponse(): Returns original response as-is (clones for logging) instead of consuming and enriching itindex.tstest/fetch-helpers.test.tsResult
Errors now display correctly in the UI:
References
opencode-copilot-auth: https://github.com/sst/opencode/blob/main/packages/opencode/src/session/message-v2.ts