internote
internote copied to clipboard
Clean up error middleware
As it stands, we throw some custom errors which should be removed in favour of the below:
The flow should be:
- Request comes in
- Lambda handler gets called
- Lambda can throw any instance of HttpError
- Database (or any other awaited service) can also throw any instance of HttpError
- 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.
- Another Middy middleware ensures that the response body is stringified for compatibility with API Gateway