You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
456 B
JavaScript
20 lines
456 B
JavaScript
4 years ago
|
function notFound(req, res, next) {
|
||
|
res.status(404);
|
||
|
const error = new Error(`Not Found - ${req.originalUrl}`)
|
||
|
next(error)
|
||
|
}
|
||
|
|
||
|
function errorHandler(err, req, res, next) {
|
||
|
const statusCode = res.statusCode !== 200 ? res.statusCode : 500
|
||
|
res.status(statusCode)
|
||
|
res.json({
|
||
|
message: err.message,
|
||
|
stack: process.env.NODE_ENV === 'production' ? '' : err.stack
|
||
|
})
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
notFound,
|
||
|
errorHandler
|
||
|
}
|