bluewave-labs / bluewave-onboarding

https://bluewavelabs.ca
GNU Affero General Public License v3.0
27 stars 19 forks source link

Custom Error Handling in Backend #323

Open mr-loop-1 opened 2 hours ago

mr-loop-1 commented 2 hours ago

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 commented 2 hours ago

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