Fix bfx api error response #327
Merged
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.
This PR enhances the error message of the
json rpcresponse. The idea is to have extra data in case we catch an error from BFX API side and on the UI use a transparent error message which can contain BFX API error reasonsinstead of proxy whole error object for error representation
Earlier we can have the following
json rpccases for errors:{ "jsonrpc": "2.0", "error": { "code": 500, "message": "Internal Server Error", "data": null }, "id": null }{ "jsonrpc": "2.0", "error": { "code": 500, "message": "Internal Server Error", "data": { "bfxApiErrorMessage": { "bfxApiStatus": 500, "bfxApiStatusText": "Internal Server Error", "bfxApiRawBodyCode": "Code is not available", "isBfxApiRawBodyResponseHtml": "No", "bfxApiRawBodyResponse": "generic error" } } }, "id": null }{ "jsonrpc": "2.0", "error": { "code": 403, "message": "Forbidden", "data": { "bfxApiErrorMessage": { "bfxApiStatus": 403, "bfxApiStatusText": "Forbidden", "bfxApiRawBodyCode": "Code is not available", "isBfxApiRawBodyResponseHtml": "Yes", "bfxApiRawBodyResponse": "Access denied | [api.staging.bitfinex.com](http://api.staging.bitfinex.com/) used Cloudflare to restrict access" } } }, "id": null }After changes we can have the following
json rpccases for errors:{ "jsonrpc": "2.0", "error": { "code": 401, "message": "Unauthorized: BFX API Error: Internal Server Error: apikey: digest invalid", "data": { "bfxApiErrorMessage": { "bfxApiStatus": 500, "bfxApiStatusText": "Internal Server Error", "bfxApiRawBodyCode": 10100, "isBfxApiRawBodyResponseHtml": false, "bfxApiRawBodyResponse": "apikey: digest invalid" } } }, "id": null }{ "jsonrpc": "2.0", "error": { "code": 500, "message": "Internal Server Error: BFX API Error: Internal Server Error: generic error", "data": { "bfxApiErrorMessage": { "bfxApiStatus": 500, "bfxApiStatusText": "Internal Server Error", "bfxApiRawBodyCode": null, "isBfxApiRawBodyResponseHtml": false, "bfxApiRawBodyResponse": "generic error" } } }, "id": null }{ "jsonrpc": "2.0", "error": { "code": 403, "message": "Forbidden: BFX API Error: Forbidden: Access denied | [api.staging.bitfinex.com](http://api.staging.bitfinex.com/) used Cloudflare to restrict access", "data": { "bfxApiErrorMessage": { "bfxApiStatus": 403, "bfxApiStatusText": "Forbidden", "bfxApiRawBodyCode": null, "isBfxApiRawBodyResponseHtml": true, "bfxApiRawBodyResponse": "Access denied | [api.staging.bitfinex.com](http://api.staging.bitfinex.com/) used Cloudflare to restrict access" } } }, "id": null }