Closed ImLunaHey closed 1 year ago
What's the recommended way of adding a 404 and global error handler?
This is now supported in v0.9. You can add a custom 404 handler as follows:
import { attachRoutes, defineRoutes } from './application';
import * as handlers from './handlers';
const port = 3000;
const fallback = defineRoutes((app) => [
app.route('*', '/*', (request) => {
return new Response('Oops, not found!', { status: 404 });
}),
]);
Bun.serve({
port,
fetch: attachRoutes(...Object.values(handlers), fallback),
});
Note: the other question from the Express docs you quoted, "How do I setup an error handler?" is not yet possible in this framework. Feel free to open a separate issue to track that if you need this functionality. I'll see about adding it.
What's the recommended way of adding a 404 and global error handler?
I'm trying to emulate this from express.
~Related: https://github.com/sstur/nbit/issues/5~ Related: https://github.com/sstur/nbit/issues/4