fix: return http error code and message when failing to connect to score-api #957
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧿 Current issues / What's wrong ?
On http error, (504, 524, etc...) where the
getScore
,getVp
andvalidate
fetch requests are unable to connect to api, the request is failing with a plaininvalid json response body at https://...
errorThis 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
instead of rejects with a
invalid json response body ...
error, which is the last "unhandled" error om these endpoint.🚧 Changes
res.json()
call, to return a JSON-RPC formatted error, with the HTTP status and message