Skip to content

Instantly share code, notes, and snippets.

@cantremember
Last active September 3, 2017 06:13
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 cantremember/98224602f7cb9e78f235 to your computer and use it in GitHub Desktop.
Save cantremember/98224602f7cb9e78f235 to your computer and use it in GitHub Desktop.
Promises: Throw or Reject
/**
* be careful to return a Promise from every exiting branch
*/
function mayReject(may) {
if (may || (may === undefined)) {
return Promise.reject(new Error('I REJECT'));
}
return Promise.resolve(true);
}
/**
* or add a candy-coated Promise shell,
* and write it more like you're used to
*/
var mayThrow = Promise.method(function(may) {
if (may || (may === undefined)) {
throw new Error('I REJECT');
}
return true;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment