josephluck / internote

:heart: Beautiful web-based note editor with a focus on distraction-free content creation.
https://internote.app
28 stars 0 forks source link

Clean up error middleware #172

Open josephluck opened 5 years ago

josephluck commented 5 years ago

As it stands, we throw some custom errors which should be removed in favour of the below:

The flow should be:

  1. Request comes in
  2. Lambda handler gets called
  3. Lambda can throw any instance of HttpError
  4. Database (or any other awaited service) can also throw any instance of HttpError
  5. When an error is thrown, it's picked up by a custom Middy middleware that checks for different instances of HttpError and returns a JSON body in the response in a known structure. Defaults to 500.
  6. Another Middy middleware ensures that the response body is stringified for compatibility with API Gateway