Skip to content

Instantly share code, notes, and snippets.

@tylerbuchea
Created December 12, 2017 23:19
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 tylerbuchea/142e8cc65f10238d164fa88fcc5a808b to your computer and use it in GitHub Desktop.
Save tylerbuchea/142e8cc65f10238d164fa88fcc5a808b to your computer and use it in GitHub Desktop.
/**
* @param { Promise } promise
* @param { Object= } errorExt - Additional Information you can pass to the err object
* @return { Promise }
*/
function to(promise, errorExt) {
return promise
.then(function (data) { return [null, data]; })
.catch(function (err) {
if (errorExt) {
Object.assign(err, errorExt);
}
return [err, undefined];
});
}
export { to };
export default to;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment