Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deferred Error Testing
require([
"dojo/Deferred"
], function(Deferred){
var useError = 0;
var getError = function(name, useThisError){
var msg = name + ' error';
if(useError || useThisError){
return function(e){ console.error(msg); d.reject(e); };
}
};
var doZap = function(){
console.log('zap');
};
var doBar = function(){
console.log('bar');
throw new Error('BAR ERROR');
};
var doFoo = function(){
console.log('foo');
};
var d = new Deferred();
d.then(
doZap,
getError('zap')
).then(
doBar, // throws an error
function(e){ console.error('e bar'); d.reject(e); } // does not get called
).then(
doFoo,
getError('foo')
);
d.resolve();
console.log('rejected:', d.isRejected(), 'fullfilled:', d.isFulfilled()); // not correct
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment