Handling RouteNotFound in Middleware for Logging

I noticed that if I use Effect.catchTags({ RouteNotFound: ... after my middleware the logger and tracer don't operate on the response I'm sending, but if I try to move the catchTags before the middleware I get a type error.

This is what I currently have set up
export const layer = router
  .pipe(
    HttpServer.router.use(Middleware.tracer),
    HttpServer.router.use(Middleware.logger),
    Effect.catchTags({
      RouteNotFound: () =>
        HttpServer.response.json(
          { message: 'Route Not Found' },
          { status: 404 },
        ),
    }),
    HttpServer.server.serve(),
  )
  .pipe(Layer.provide(Server.layer));

Is there a way to use the same logs/spans for the ServerResponse from Effect.catchTags as I do from regular routes?
I've tried both HttpServer.router.catchTags (doesn't see RouteNotFound) and trying to catch in a middleware (type errors, didn't work, probably misguided)
Was this page helpful?