-
Notifications
You must be signed in to change notification settings - Fork 24
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
Custom Error Handling in Backend #323
Comments
@gorkem-bwl @uparkalau @erenfn what are your opinions on this. I can work on this in case. |
Sure, this was something I had in mind as well. We need to ensure that errors are standardized. You can go ahead. |
@erenfn can you tell what is this for
|
It adds the error code (such as 401 or 500) to the payload. I think the if statement is included as a precaution. |
@erenfn the status code is separately there in the function. |
Oh I see. I don't know where that is used either. @uparkalau may give you a better answer |
Hey @mr-loop-1 , how is this going? Do you still need help? |
I made several controllers and services in backend and felt a constant need of more specific error handling and sending tailored messages back in responses. Currently, there is no way to differentiate between errors thrown manually by us and those thrown automatically like type check or db error.
Importantly, while catching errors it can't be determined what kind of error it is. The desired feature is to send specific error messages and status codes to frontend so that they can be handled easily in toast etc.
One solution is to create a custom error class extending the javascript error with extra properties. Additionally, since there will be repeated logic regarding this, an error middleware should be created that sits after the controller's catch block.
The text was updated successfully, but these errors were encountered: