Closed marcushill closed 7 years ago
For instance, invalid X-USER-ID returns:
{ "error": "User does not exist" }
TLDR: Just throw an exception. I'll catch it.
I'm starting a global exception handler and introducing custom exceptions that should help with this. Ideally, if you have an error in a piece of the business logic, you should just throw an exception (possibly with a status code) and move on. We shouldn't have to track down all the route handlers to add duplicate try catch statements.
Done. Now, you can get a properly formatted error from the API by throwing an Exception/Error. If you use the custom TroubadourError, you're also allowed to specify a status code. (Or you could just set status on a plain old Error object. Gotta love duck typing).