From 681ca574c59ea818be266166767d17b2c8fe6ff6 Mon Sep 17 00:00:00 2001 From: Guilherme Hermeto Date: Tue, 7 Jul 2020 00:55:15 -0700 Subject: [PATCH] fix: add method and path to AsyncError --- lib/chain.js | 9 ++++++++- test/chain.test.js | 3 +++ test/server.test.js | 25 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/chain.js b/lib/chain.js index b5c83b0e5..42f62d551 100644 --- a/lib/chain.js +++ b/lib/chain.js @@ -178,7 +178,14 @@ function call(handler, err, req, res, _next) { function reject(error) { if (!(error instanceof Error)) { error = new customErrorTypes.AsyncError( - { info: { cause: error, handler: handler._name } }, + { + info: { + cause: error, + handler: handler._name, + method: req.method, + path: req.path ? req.path() : undefined + } + }, 'Async middleware rejected without an error' ); } diff --git a/test/chain.test.js b/test/chain.test.js index acaf931fe..77081a896 100644 --- a/test/chain.test.js +++ b/test/chain.test.js @@ -361,6 +361,9 @@ test('abort with rejected promise without error', function(t) { endHandlerTimer: function() {}, closed: function() { return false; + }, + path: function() { + return '/'; } }, {}, diff --git a/test/server.test.js b/test/server.test.js index cca446462..2c9f514f1 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -2903,6 +2903,31 @@ test('async prerouting chain with error', function(t) { }); }); +test('async prerouting chain with empty rejection', function(t) { + SERVER.pre(async function(req, res) { + await helper.sleep(10); + return Promise.reject(); + }); + + SERVER.get('/hello/:name', function tester(req, res, next) { + res.send(req.params.name); + next(); + }); + + SERVER.on('Async', function(req, res, err, callback) { + t.equal(err.jse_info.cause, undefined); + t.equal(err.jse_info.method, 'GET'); + t.equal(err.jse_info.path, '/hello/mark'); + callback(); + }); + + CLIENT.get('/hello/mark', function(err, _, res) { + t.ok(err); + t.equal(res.statusCode, 500); + t.end(); + }); +}); + test('async use chain with error', function(t) { SERVER.use(async function(req, res) { await helper.sleep(10);