Skip to content

Instantly share code, notes, and snippets.

@jinalshah999
Created January 30, 2021 11:52
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 jinalshah999/9bba693c435c3115dccf82979c67e7c6 to your computer and use it in GitHub Desktop.
Save jinalshah999/9bba693c435c3115dccf82979c67e7c6 to your computer and use it in GitHub Desktop.
bindResponse(req, res, next) {
this.request = req;
res.sendResponse = (response) => {
res.json({
status: 'success',
data: response
});
};
res.sendError = (error) => {
if(error.httpCode) {
res.status(error.httpCode);
}
res.json({
status: 'error',
error: error.code ? error.getError(): error
});
};
next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment