-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Per-controller error handling #335
Comments
I was facing this same issue. Here's how we managed that: 1 - Create a handler file with the HTTP responses:
2 - Create a middleware to bind in the setup and to call the Handler class
3 - Config your app to bind the middleware
4 - Try/catch your controller and use the 'next' function in the catch block. It'll automatically call the middleware as we are using the Chain of Responsability.
And if you want to log the errors, you can call your logger (we are using winston) in the Handler just before the return, as below:
|
I couldn't find a way to handle all errors in a controller in one handler.
For example:
It's not working also in application level,
Is there an elegant way to handle errors without repeating the code? (If I want for example to log any error to some logger)?
The text was updated successfully, but these errors were encountered: