1.0.3 • Published 2 years ago
@bii811/genmvccrud v1.0.3
Instructions
utils/catchAsync.js
module.exports = fn => {
return (req, res, next) => {
fn(req, res, next).catch(next)
}
}
utils/appError.js
class AppError extends Error {
constructor(message, statusCode) {
super(message)
this.statusCode = statusCode
this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'
this.isOperational = true;
Error.captureStackTrace(this, this.constructor)
}
}
module.exports = AppError
add this to app.js
app.all('*', (req, res, next)=>{
const err = new Error(`Can't find ${req.originalUrl} on this server!`)
err.status = 'fail'
err.statusCode = 404
next(err)
})