Skip to content
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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

ai16z-demirix
Copy link
Contributor

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.

@ai16z-demirix
Copy link
Contributor Author

@monilpat Please check this, regarding issue #1735
Created proposition how it can look, if the error messages are now clear and reasonable.

@ai16z-demirix ai16z-demirix changed the title refactor: (draft) improving API error handling for coinbase integration refactor: (prop) improving API error handling for coinbase integration Jan 3, 2025
Comment on lines 39 to 41
function parseErrorResponse(responseText: string): Record<string, any> {
try {
return JSON.parse(responseText);

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.

Copy link
Contributor Author

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

Comment on lines 118 to 121
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);

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.

Copy link
Contributor Author

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

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.

2 participants