node-express-mongodb-jwt-rest-api-skeleton
Version:
Node.js express.js MongoDB JWT REST API - This is a basic API REST skeleton written on JavaScript using async/await. Great for building a starter web API for your front-end (Android, iOS, Vue, react, angular, or anything that can consume an API)
20 lines (18 loc) • 472 B
JavaScript
/**
* Handles error by printing to console in development env and builds and sends an error response
* @param {Object} res - response object
* @param {Object} err - error object
*/
const handleError = (res = {}, err = {}) => {
// Prints error in console
if (process.env.NODE_ENV === 'development') {
console.log(err)
}
// Sends error to user
res.status(err.code).json({
errors: {
msg: err.message
}
})
}
module.exports = { handleError }