Skip to content

Commit 123e8ff

Browse files
committed
added old errors
1 parent 503a668 commit 123e8ff

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/app.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,29 @@ app.use(launches.routes());
5555
app.use(upcoming.routes());
5656
app.use(parts.routes());
5757

58-
// Error Handler
58+
// 500 Error Handler
5959
app.use(async (ctx, next) => {
6060
try {
6161
await next();
6262
} catch (err) {
6363
ctx.status = err.status || 500;
64-
ctx.body = err.message;
64+
ctx.body = {
65+
error: 'No results found',
66+
};
67+
ctx.app.emit('error', err, ctx);
68+
}
69+
});
70+
71+
// 404 Error Handler
72+
app.use(async (ctx, next) => {
73+
try {
74+
await next();
75+
if (ctx.status === 404) ctx.throw(404);
76+
} catch (err) {
77+
ctx.throw(err);
78+
ctx.body = {
79+
error: 'Internal Server Error',
80+
}
6581
ctx.app.emit('error', err, ctx);
6682
}
6783
});

0 commit comments

Comments
 (0)