13 lines
262 B
JavaScript
13 lines
262 B
JavaScript
function withErrorHandling(handler) {
|
|
return async (req, res) => {
|
|
try {
|
|
await handler(req, res);
|
|
} catch (error) {
|
|
console.error(error);
|
|
res.status(error.status || 500).end(error.message);
|
|
}
|
|
};
|
|
}
|
|
|
|
export { withErrorHandling };
|