Skip to content

Commit

Permalink
Extend RouterResponder to conform to RouterMiddleware.
Browse files Browse the repository at this point in the history
This means we can add a Router (eg one built with OpenAPI) into a RouterBuilder from HummingbirdRouter
  • Loading branch information
adam-fowler committed Apr 21, 2024
1 parent 4283ebe commit dd83a0a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Sources/Hummingbird/Router/RouterResponder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,14 @@ public struct RouterResponder<Context: BaseRequestContext>: 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)
}
}
}

0 comments on commit dd83a0a

Please sign in to comment.