File size: 513 Bytes
072e993 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
export class Middleware2 extends plugin {
constructor () {
super({
name: '中间件',
priority: 9 ** 9,
rule: [
{
method: 'use',
use: ['Invalid', 'Error']
}
]
})
}
Invalid (req, res) {
if (!res.writableEnded) {
res.status(404).render('404')
}
}
Error (err, req, res, next) {
if (!res.writableEnded) {
res.send({ status: 1, message: 'Error occurred!' })
}
if (err) {
logger.error(err)
}
}
} |