Add request logging to asyncHandler
This commit is contained in:
parent
4774e61d50
commit
370a7f7d6c
|
@ -1,12 +1,12 @@
|
||||||
/**
|
/**
|
||||||
* Useful for wrapping `async` request handlers so they
|
* Useful for wrapping `async` request handlers in Express
|
||||||
* automatically propagate errors.
|
* so they automatically propagate errors.
|
||||||
*/
|
*/
|
||||||
export default function asyncHandler(handler) {
|
export default function asyncHandler(handler) {
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
Promise.resolve(handler(req, res, next)).catch(error => {
|
Promise.resolve(handler(req, res, next)).catch(error => {
|
||||||
console.error(`Unexpected error in ${handler.name}!`);
|
req.log.error(`Unexpected error in ${handler.name}!`);
|
||||||
console.error(error);
|
req.log.error(error.stack);
|
||||||
|
|
||||||
next(error);
|
next(error);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue