routing-controllers icon indicating copy to clipboard operation
routing-controllers copied to clipboard

A catch-all 404 handler for koa?

Open slavafomin opened this issue 1 year ago • 0 comments

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 avatar Aug 05 '22 16:08 slavafomin