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

Improve error handling #16

Merged
merged 4 commits into from
Feb 13, 2024
Merged

Improve error handling #16

merged 4 commits into from
Feb 13, 2024

Conversation

mariavarvaroi
Copy link
Contributor

Return an error in these scenarios:

  • the response status is 200, but it contains an errors field
  • the data field is missing
  • the fields for the response that are supposed to be arrays have length 0

Test fixes:
Now that we return errors for length 0 arrays, we need to mock graphql responses for certain tests

src/api/rewardsHistory.ts Outdated Show resolved Hide resolved
src/api/vaultDetails.ts Outdated Show resolved Hide resolved
@mksh
Copy link
Contributor

mksh commented Feb 12, 2024

It seems there are no tests right now that would check new error handling code; while I don't think we need to cover every API method error handling, if we extract common error handling logic it can be tested just once for 1 API method.

While it's not possible to make real Stakewise backend to return errors on-demand, we can use mocking of fetch method (inside connector.graphqlRequest) to emulate response containing errors, see examples via https://www.leighhalliday.com/mock-fetch-jest

Copy link
Contributor

@welldan97 welldan97 left a comment

Choose a reason for hiding this comment

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

Looking good!

Copy link
Contributor

@mksh mksh left a comment

Choose a reason for hiding this comment

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

LGTM

@mariavarvaroi mariavarvaroi merged commit d3a42d6 into main Feb 13, 2024
1 check passed
@mariavarvaroi mariavarvaroi deleted the improve-error-handling branch February 13, 2024 13:21
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