This commit is contained in:
payacom
2026-08-31 20:45:41 +03:30
parent fa9f23c61d
commit 3f416a7a60
367 changed files with 621895 additions and 6443 deletions

20
utils/asyncHandler.js Normal file
View File

@@ -0,0 +1,20 @@
function asyncHandler (handler) {
return (req, res, next) => {
Promise.resolve(handler(req, res, next)).catch((error) => {
console.error('[asyncHandler]', error)
if (res.headersSent) {
return next(error)
}
const status = error?.status || 500
return res.status(status).json({
message: error?.userMessage || 'خطای سرور',
en_message: error?.message || 'internal_error',
})
})
}
}
module.exports = asyncHandler
module.exports.asyncHandler = asyncHandler