-
Notifications
You must be signed in to change notification settings - Fork 41
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
Refactored Error Handleing. Modified Country API using new error hand… #173
base: development
Are you sure you want to change the base?
Refactored Error Handleing. Modified Country API using new error hand… #173
Conversation
@anjula-sack what do you think on this approach. Throw errors based on a cusom error object within the service. will be handled via a middleware function. Error handling will be done in a centralized object so that we can extend it. Custom Error will also be extensible. to reduce the try/catch, an async handle will be used in the route level. Used this approach in another project before. We can use the services without repetition. Also, in a case where we need to check if a record is null, then we can use a try/catch (only when necassary) within the service which we use to integrate a funtion from another service. We can also send a standardized response with a util method to create a response object Service:
Controller:
Route:
App:
AppError:
ErrorHandler:
AsyncHandler:
|
I really like this approach. We can keep creating few error types like, ResourceNotFound to handle the other cases. @Disura-Randunu |
@anjula-sack we can actually create some sort of enum based error type object and use that to inject different details of the error prperties while having a single Error class. that way we can extend it however we want and keep adding new errorTypes to the enum. Will update on that so we can make sure if its good |
@anjula-sack
We can throw the error within service like below
OR We can throw a custom error like below:
We can also make it so that ERROR NAME must be of AppErrorType enum to strict the error types. Then we just have to add that new error for the enum to make use of that insteaad of just any string. ***This is when creating a custom error. |
…ling
Purpose
The purpose of this PR is to fix #
Goals
Approach
Screenshots
Checklist
Related PRs
Test environment
Learning