-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
refactor: (prop) improving API error handling for coinbase integration #1777
base: develop
Are you sure you want to change the base?
Conversation
function parseErrorResponse(responseText: string): Record<string, any> { | ||
try { | ||
return JSON.parse(responseText); |
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.
@ai16z-demirix The parseErrorResponse function should handle cases where responseText is not a valid JSON string. Consider logging the error or throwing a specific error to aid debugging.
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.
Good point. Introduced new changes @lostgirldev
if ((400 <= response.status && response.status <= 499) || | ||
(500 <= response.status && response.status <= 599)) { | ||
const errorDetails = getErrorDetails(response, responseText); | ||
throw new CoinbaseError(errorDetails, response.status, response); |
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.
@ai16z-demirix Ensure that the error handling in handleException does not expose sensitive information. The error message should be sanitized before being thrown to avoid leaking details about the API or system.
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.
Good point and thank you. Introduced new changes. @lostgirldev
…dling for non-JSON responses.
Relates to:
#1735
Risks
Medium: Error handling in Coinbase integration can be affected.
Background
What does this PR do?
This PR improves handling for APi errors from Coinbase.
What kind of change is this?
Improvement.
Regarding issue: #1735
Documentation changes needed?
My changes do not require a change to the project documentation.
Testing
Where should a reviewer start?
Changed files:
packages/plugin-coinbase/advanced-sdk-ts/src/rest/errors.ts
packages/plugin-coinbase/advanced-sdk-ts/src/rest/rest-base.ts
Detailed testing steps
Running agent and try to consume Coinbase API.