这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@ZIMkaRU
Copy link
Member

@ZIMkaRU ZIMkaRU commented Aug 17, 2023

This PR enhances the error message of the json rpc response. 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 reasons

res?.error?.message

instead of proxy whole error object for error representation


Earlier we can have the following json rpc cases for errors:

  • if internal error:
{
  "jsonrpc": "2.0",
  "error": {
    "code": 500,
    "message": "Internal Server Error",
    "data": null
  },
  "id": null
}
  • if error came from BFX API:
{
  "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
}
  • if error came from BFX API as HTML:
{
  "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 rpc cases for errors:

  • if error came from BFX API:
{
  "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
}
  • if error came from BFX API as HTML:
{
  "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
}

Copy link
Contributor

@ezewer ezewer left a comment

Choose a reason for hiding this comment

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

looks good to me!

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