1.0.3 • Published 2 years ago

@bii811/genmvccrud v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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)
})
1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago