Report deferred exceptions via callback

This commit is contained in:
Raymond Feng 2015-08-05 11:18:20 -07:00
parent fa570a9514
commit 21c0067462
1 changed files with 18 additions and 3 deletions

View File

@ -2072,7 +2072,20 @@ DataSource.prototype.ready = function (obj, args) {
if (timeoutHandle) {
clearTimeout(timeoutHandle);
}
method.apply(obj, [].slice.call(args));
var params = [].slice.call(args);
try {
method.apply(obj, params);
} catch (err) {
// Catch the exception and report it via callback
var cb = params.pop();
if (typeof cb === 'function') {
process.nextTick(function() {
cb(err);
});
} else {
throw err;
}
}
};
onError = function (err) {
// Remove the connected listener
@ -2083,7 +2096,9 @@ DataSource.prototype.ready = function (obj, args) {
var params = [].slice.call(args);
var cb = params.pop();
if (typeof cb === 'function') {
process.nextTick(function() {
cb(err);
});
}
};
this.once('connected', onConnected);