mcwebb / lambda-kernel

Minimal kernel to handle and provide structure to requests and responses for AWS Lambda and Serverless
MIT License
2 stars 0 forks source link

Allow throwing custom errors which map to different HTTP error codes #4

Open mcwebb opened 7 years ago

mcwebb commented 7 years ago

Occasionally, in a promise chain for example, one may want to throw an error which doesn't cause a 500 response, because sometimes there are runtime errors which deserver a 400 response because it's the users fault.

Potentially there should be some custom errors which can be picked up by the dispatcher so that the application can easily tailor what error response is given to the client.

mcwebb commented 7 years ago

Probably pertains to #3.

mcwebb commented 7 years ago

Turns out this is actually possible by adding the code between square brackets somewhere in the error message (see 5540685), but that seems like a bit of a janky solution, and could lead to confusing behaviour if someone happens to include a number that matches the regex in their message but isn't actually a HTTP code.

At the very least the regex should be tightened to only accept valid HTTP codes.