feat(pkg): error handling

This commit is contained in:
DIYgod
2019-09-19 18:15:51 +08:00
parent 2aa847c71c
commit 7bdda509fe
4 changed files with 28 additions and 24 deletions

View File

@@ -26,13 +26,24 @@ module.exports = async (ctx, next) => {
message = err.stack;
}
logger.error(`Error in ${ctx.request.path}: ${message}`);
ctx.set({
'Content-Type': 'text/html; charset=UTF-8',
});
ctx.body = art(path.resolve(__dirname, '../views/error.art'), {
message,
});
ctx.status = 404;
if (config.isPackage) {
ctx.body = {
error: {
message: err.message,
},
};
} else {
ctx.set({
'Content-Type': 'text/html; charset=UTF-8',
});
ctx.body = art(path.resolve(__dirname, '../views/error.art'), {
message,
});
if (ctx.status !== 403) {
ctx.status = 404;
}
}
if (!ctx.debug.errorPaths[ctx.request.path]) {
ctx.debug.errorPaths[ctx.request.path] = 0;