divyansh-2005 / my-calendar-app

My Calendar App is a full-stack application designed to help users manage their schedules, expenses, todos, and notes all in one place. The app provides a seamless and intuitive user interface for efficient day-to-day management and includes robust backend support for secure data handling and user authentication.
https://my-calendar-app-phi.vercel.app
22 stars 51 forks source link

[FEATURE] Adding a common Async Handler Utility. #38

Closed MOHINI1403 closed 1 month ago

MOHINI1403 commented 1 month ago

Is your feature request related to a problem? Please describe.

I am proposing of writing the common utility AsyncHandler which is going to eliminate the need for try...catch block in every route. If an error occurs in an asynchronous code inside the handler, the asyncHandler will catch it and respond with a structured error message.

Describe the solution you'd like

const registerUser = asyncHandler(async (req, resp) => {
  // Your registration logic here...
});

const loginUser = asyncHandler(async (req, resp) => {
  // Your login logic here...
});

Wrapping my Controller logic within this AsyncHandler utility.

Why I am Proposing this ?? Writing try...catch for every controller is cumbersome and it's a good practise to use try...catch while writing the controllers with this utility we can focus on writing the try...catch block once and just importing this utility and wrapping our function in this as mentioned above . Screenshots If applicable, add screenshots to help explain your problem.

screenshots/video of feature Add any other context or screenshots about the feature request here.

check list