Skip to content

Instantly share code, notes, and snippets.

@glepur
Created May 14, 2018 15:55
Show Gist options
  • Select an option

  • Save glepur/0304e6d57fc2bd68d28ea7a78aedf5dd to your computer and use it in GitHub Desktop.

Select an option

Save glepur/0304e6d57fc2bd68d28ea7a78aedf5dd to your computer and use it in GitHub Desktop.
Improved promise and error handling in nodejs.
//*** HELPER FUNCTIONS ***
//*** npm install parse-error
pe = require('parse-error');
to = function(promise) {
return promise
.then(data => {
return [null, data];
}).catch(err =>
[pe(err)]
);
};
TE = function(err_message, log){ // TE stands for Throw Error
if(log === true){
console.error(err_message);
}
throw new Error(err_message);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment