Skip to content

Instantly share code, notes, and snippets.

@joewalker
Last active December 11, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joewalker/4608678 to your computer and use it in GitHub Desktop.
Save joewalker/4608678 to your computer and use it in GitHub Desktop.
Logging errors in promises
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
// ...
/**
* Internal utility: Decorates given `f` function, so that on exception promise
* rejected with thrown error is returned.
*/
function attempt(f) {
return function effort(input) {
try {
return f(input);
}
catch(error) {
console.error(error);
return rejected(error);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment