diff options
author | Reed Feng <reed.feng@autodesk.com> | 2018-08-03 02:13:46 +0800 |
---|---|---|
committer | Alex Early <alexander.early@gmail.com> | 2018-08-02 11:13:46 -0700 |
commit | 5c174fa63b5a7197ff6abe19a97b74ed7e77646d (patch) | |
tree | 7bb23733cde4a0a0e7125830e88207b42c21af33 | |
parent | 3741f80b958bd6afde7fa39af55cea886e8bb3ad (diff) | |
download | async-5c174fa63b5a7197ff6abe19a97b74ed7e77646d.tar.gz |
[issue-1568][bug]: make sure error object defined before access its message (#1569)
-rw-r--r-- | lib/asyncify.js | 2 | ||||
-rw-r--r-- | test/asyncify.js | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/asyncify.js b/lib/asyncify.js index 168f88a..2457377 100644 --- a/lib/asyncify.js +++ b/lib/asyncify.js @@ -87,7 +87,7 @@ function handlePromise(promise, callback) { return promise.then(value => { invokeCallback(callback, null, value); }, err => { - invokeCallback(callback, err.message ? err : new Error(err)); + invokeCallback(callback, err && err.message ? err : new Error(err)); }); } diff --git a/test/asyncify.js b/test/asyncify.js index 225f6d4..f76c0a7 100644 --- a/test/asyncify.js +++ b/test/asyncify.js @@ -91,6 +91,19 @@ describe('asyncify', () => { }); }); + it('reject without reason', (done) => { + var promisified = function() { + return new Promise(((resolve, reject) => { + reject(); + })); + }; + async.asyncify(promisified)("argument", (err) => { + assert(err); + expect(err.message).to.eql(''); + done(); + }); + }); + it('callback error @nodeonly', (done) => { expectUncaughtException(); |