Skip to content

Instantly share code, notes, and snippets.



Last active Dec 25, 2015
What would you like to do?
helper function to reduce mongoose/REST boilerplate. Could also monkey patch into OutgoingMessage.prototype perhaps.
function oopsAPI(res, error, model) {
if (error) {
logger.error('Unexpected mongoose error during API query', error);
return true;
if (!model) {
return true;
return false;
//to use in an API route handler
someQuery.exec(function (error, model) {
if (oopsAPI(res, error, model)) { return; }
//success code here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.