CodeHub Branch Setup

This commit is contained in:
Angad Chauhan
2025-06-23 18:55:08 +05:30
commit 2c8e3de2f5
56 changed files with 6850 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
/**
* Asynchronous error handler for Express routes.
* @function AsyncHandler
*
* @param {Function} fn - Asynchronous function to be executed.
* @returns {Function} Middleware function that handles errors for asynchronous routes.
*/
module.exports.AsyncHandler = (fn) => (req, res, next) => {
// Wrap the asynchronous function in a promise and handle any errors by passing them to the next middleware.
Promise.resolve(fn(req, res, next)).catch(next);
};