basic error handling
This commit is contained in:
parent
dbe4511c62
commit
54ddca9477
1 changed files with 9 additions and 0 deletions
|
@ -9,6 +9,15 @@ const redirectMiddleware = require('./middleware/redirect');
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
const DIST_ROOT = path.resolve(__dirname, 'dist');
|
const DIST_ROOT = path.resolve(__dirname, 'dist');
|
||||||
|
|
||||||
|
app.use(async (ctx, next) => {
|
||||||
|
try {
|
||||||
|
await next();
|
||||||
|
} catch (err) {
|
||||||
|
ctx.status = err.status || 500;
|
||||||
|
ctx.body = err.message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
app.use(logger());
|
app.use(logger());
|
||||||
app.use(redirectMiddleware);
|
app.use(redirectMiddleware);
|
||||||
app.use(serve(DIST_ROOT)); // Check if the request url matches any assets inside of /dist
|
app.use(serve(DIST_ROOT)); // Check if the request url matches any assets inside of /dist
|
||||||
|
|
Loading…
Reference in a new issue