trustwallet / blockatlas

Clean and lightweight cross-chain transaction API
MIT License
371 stars 230 forks source link

[Platform] Define Error Response #836

Closed vikmeup closed 4 years ago

vikmeup commented 4 years ago

Summary of Bug

Currently error response type has duplicated data and not intuitive to use

{
   "code":500,
   "error":{
      "error":"Validator not found: Unable to fetch delegations list",
      "meta":{
         "Balance":"5383274",
         "Delegate":"tz1egbN6RK2bM5vt4aAZw6r9j4nL8z49bPdS"
      }
   }
}

Expected Behavior

TODO: Define

arein commented 4 years ago

What does "Validator not found" mean - should this also be a HTTP 404 error code? The summary hints at this being a HTTP 500 status

vikmeup commented 4 years ago

Yes, there is two problems:

1) wrong status code 2) error response is not well designed, there is an error value inside an error object

EnoRage commented 4 years ago

Let's design a new version of handlers for Platform REST API? I recommend reading that before https://github.com/microsoft/api-guidelines https://medium.com/@schneidenbach/restful-api-best-practices-and-common-pitfalls-7a83ba3763b5

arein commented 4 years ago

+1

vikmeup commented 4 years ago
{
    "error": {
        "code": 123,
        "message": "Link alias conflict"
    }
}
{
    "error": {
        "code": 123,
        "message": "Some error"
    }
}

Best format for errors.

thomasxnguy commented 4 years ago

Some remarks about the error handling :

An example of list of error code

https://docs.aws.amazon.com/AWSEC2/latest/APIReference/errors-overview.html

riptl commented 4 years ago

I recommend RFC 7807: "Problem Details for HTTP APIs". Simple and widely used. https://tools.ietf.org/html/rfc7807#section-3

EnoRage commented 4 years ago

1015