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

fix: return http error code and message when failing to connect to score-api #957

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Jan 28, 2024

🧿 Current issues / What's wrong ?

On http error, (504, 524, etc...) where the getScore, getVp and validate fetch requests are unable to connect to api, the request is failing with a plain invalid json response body at https://... error

This does not have any indications on the caller side why the error is failing, and making it difficult to handle (should retry?)

💊 Fixes / Solution

API already return a well formatted JSON-RPC error, only cases where this json parsing error happens is for HTML response returned by cloudflare

We should return a meaningful JSON-RPC error when the HTTP request to the API is failing.

Example, on a timeout http error from cloudflare, the request will now rejects with

{
      code: 524,
      message: 'Gateway timeout',
      data: ''
    }

instead of rejects with a invalid json response body ... error, which is the last "unhandled" error om these endpoint.

🚧 Changes

  • Try/Catch the res.json() call, to return a JSON-RPC formatted error, with the HTTP status and message

Copy link

sentry-io bot commented Jan 28, 2024

Sentry issue: SNAPSHOT-SEQUENCER-3

@wa0x6e wa0x6e requested a review from ChaituVR January 28, 2024 16:28
Copy link

codecov bot commented Jan 28, 2024

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Files Patch % Lines
src/utils.ts 68.88% 14 Missing ⚠️
Additional details and impacted files

📢 Thoughts on this report? Let us know!

@wa0x6e wa0x6e self-assigned this Jan 29, 2024
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