Created
October 20, 2014 20:14
-
-
Save cburgmer/849e1d0eff709bd02c10 to your computer and use it in GitHub Desktop.
Debuggable promise exceptions, see https://github.com/cburgmer/ayepromise/pull/8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (root, factory) { | |
if (typeof define === 'function' && define.amd) { | |
define(['ayepromise'], factory); | |
} else if (typeof exports === 'object') { | |
module.exports = factory(require('ayepromise')); | |
} else { | |
root.ayepromise = factory(root.ayepromise); | |
} | |
}(this, function (ayepromise) { | |
'use strict'; | |
var debuggable = { | |
suppressedErros: [], | |
debugMode: false | |
}; | |
var logError = function(e) { | |
if(debuggable.debugMode) { | |
debuggable.suppressedErros.push(e); | |
if(console) { | |
console.error('The following error was thrown, but suppressed by ayepromise, you can debug with in debuggable.suppressedErros.', e); | |
} | |
} | |
}; | |
var adaptPromise = function (promise) { | |
return promise.then(null, function (e) { | |
logError(e); | |
throw e; | |
}); | |
}; | |
debuggable.defer = function () { | |
var defer = ayepromise.defer(); | |
return { | |
resolve: defer.resolve, | |
reject: defer.reject, | |
promise: adaptPromise(defer.promise) | |
}; | |
}; | |
return debuggable; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment