Repository: caolan/async (js)

Issue:
Make sure error object is defined before access its message
https://github.com/caolan/async/blob/master/lib/asyncify.js#L90
``` javascript
function handlePromise(promise, callback) {
    return promise.then(value => {
        invokeCallback(callback, null, value);
    }, err => {
        invokeCallback(callback, err.message ? err : new Error(err));
    });
}
```
`err && err.message` will be better when I happened to reject a promise without reason.


Pull request description:
[issue-1568][bug]: make sure error object defined before access its message
fix #1568 

Patch:
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));
     });
 }
 


Test patch:
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();