internote icon indicating copy to clipboard operation
internote copied to clipboard

Clean up error middleware

Open josephluck opened this issue 5 years ago • 0 comments

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

josephluck avatar Aug 07 '19 08:08 josephluck