diff --git a/Sources/Hummingbird/Router/RouterResponder.swift b/Sources/Hummingbird/Router/RouterResponder.swift index c4abec9ae..05ffa46c5 100644 --- a/Sources/Hummingbird/Router/RouterResponder.swift +++ b/Sources/Hummingbird/Router/RouterResponder.swift @@ -57,3 +57,14 @@ public struct RouterResponder: HTTPResponder { return try await responder.respond(to: request, context: context) } } + +extension RouterResponder: RouterMiddleware { + /// Treat RouterResponder as a Middleware + public func handle(_ request: Request, context: Context, next: (Request, Context) async throws -> Response) async throws -> Response { + do { + return try await self.respond(to: request, context: context) + } catch let error as HTTPError where error.status == .notFound { + return try await next(request, context) + } + } +}