Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A catch-all 404 handler for koa? #906

Open
slavafomin opened this issue Aug 5, 2022 · 0 comments
Open

A catch-all 404 handler for koa? #906

slavafomin opened this issue Aug 5, 2022 · 0 comments
Labels
type: question Questions about the usage of the library.

Comments

@slavafomin
Copy link
Contributor

slavafomin commented Aug 5, 2022

Hello!

I'm trying to implement a pretty trivial thing — a catch-all handler that will return 404 when request handler is not found for the request in question, however, I can't find any related examples in the docs. What is the best practice for this? I'm using koa.

If I add the following middleware, then it will overwrite the response data from the controller:

app.use(context => {
  context.status = 404;
  context.body = {
    message: 'Not found',
  };
});
@slavafomin slavafomin added the type: question Questions about the usage of the library. label Aug 5, 2022
@slavafomin slavafomin changed the title A catch-all handler for koa? A catch-all 404 handler for koa? Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Questions about the usage of the library.
Development

No branches or pull requests

1 participant