[go: up one dir, main page]

Skip to content
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

Open
mr-loop-1 opened this issue Oct 26, 2024 · 7 comments
Open

Custom Error Handling in Backend #323

mr-loop-1 opened this issue Oct 26, 2024 · 7 comments

Comments

@mr-loop-1
Copy link
Contributor
mr-loop-1 commented Oct 26, 2024

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.

@mr-loop-1
Copy link
Contributor Author
mr-loop-1 commented Oct 26, 2024

@gorkem-bwl @uparkalau @erenfn what are your opinions on this. I can work on this in case.

@erenfn
Copy link
Collaborator
erenfn commented Oct 26, 2024

Sure, this was something I had in mind as well. We need to ensure that errors are standardized. You can go ahead.

@mr-loop-1
Copy link
Contributor Author

@erenfn can you tell what is this for

@erenfn
Copy link
Collaborator
erenfn commented Oct 30, 2024

It adds the error code (such as 401 or 500) to the payload. I think the if statement is included as a precaution.

@mr-loop-1
Copy link
Contributor Author
mr-loop-1 commented Oct 30, 2024

@erenfn the status code is separately there in the function.
currently simple strings like 'CREATE_HINT_ERROR' is being passed but I am not sure where this is used.

@erenfn
Copy link
Collaborator
erenfn commented Oct 30, 2024

Oh I see. I don't know where that is used either. @uparkalau may give you a better answer

@erenfn
Copy link
Collaborator
erenfn commented Nov 5, 2024

Hey @mr-loop-1 , how is this going? Do you still need help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants