hirosystems / stacks-blockchain-api

API for the Stacks blockchain
https://stacks-blockchain-api.vercel.app
GNU General Public License v3.0
178 stars 114 forks source link

Review error handling #173

Closed agraebe closed 4 years ago

agraebe commented 4 years ago

We should ensure that all errors returned by the API follow the same structure and have an appropriate error response code. For the base structure, I'd propose RFC 7807:

{
  "type": "https://example.com/probs/out-of-credit", 
  "title": "You do not have enough credit.", 
  "detail": "Your current balance is 30, but that costs 50.",
}

We'd need docs URLs for these to work. This will require us to document errors in our docs, which is a great thing I'd argue.

zone117x commented 4 years ago

I think we can possibly close this issue. All sidecar endpoints that result in a non-2xx status code return a json object with an error property. This is already being used by some consumer projects which do something like:

const result = await fetch(...)
if (!result.ok) {
  const error = await result.json();
  throw new Error(error);
}

Additionally, I think the core-node proxied endpoints are returning a similar error structure (going off memory since I can't seem to get core-node to error atm). And if we did something like standardize on RFC 7807, we'd wouldn't want to be doing transforms on the proxied endpoints, so we'd probably need to make those changes to the rust codebase as well.

Thoughts?

agraebe commented 4 years ago

Agreed