diff --git a/Sources/Hummingbird/Middleware/FileMiddleware.swift b/Sources/Hummingbird/Middleware/FileMiddleware.swift index 73e5a10ad..e109b1930 100644 --- a/Sources/Hummingbird/Middleware/FileMiddleware.swift +++ b/Sources/Hummingbird/Middleware/FileMiddleware.swift @@ -97,7 +97,7 @@ public struct FileMiddleware: R return try await next(request, context) } catch { // Guard that error is HTTP error notFound - guard let httpError = error as? HTTPError, httpError.status == .notFound else { + guard let httpError = error as? HTTPResponseError, httpError.status == .notFound else { throw error } diff --git a/Sources/HummingbirdRouter/RouteGroup.swift b/Sources/HummingbirdRouter/RouteGroup.swift index fed6bf06f..a362f1f4b 100644 --- a/Sources/HummingbirdRouter/RouteGroup.swift +++ b/Sources/HummingbirdRouter/RouteGroup.swift @@ -19,8 +19,8 @@ public struct RouteGroup: ServerChildChannel { } } - @inlinable /// handle messages being passed down the channel pipeline /// - Parameters: /// - value: Object to process input/output on child channel /// - logger: Logger to use while processing messages + @inlinable public func handle(value: BaseChannel.Value, logger: Logging.Logger) async { await self.baseChannel.handle(value: value, logger: logger) } diff --git a/Tests/HummingbirdTests/FileMiddlewareTests.swift b/Tests/HummingbirdTests/FileMiddlewareTests.swift index e7edb39e6..5efa74248 100644 --- a/Tests/HummingbirdTests/FileMiddlewareTests.swift +++ b/Tests/HummingbirdTests/FileMiddlewareTests.swift @@ -316,6 +316,34 @@ final class FileMiddlewareTests: XCTestCase { } } + func testOnThrowCustom404() async throws { + let router = Router() + router.middlewares.add(FileMiddleware(".", searchForIndexHtml: true)) + struct Custom404Error: HTTPResponseError { + var status: HTTPResponse.Status { .notFound } + + func response(from request: Request, context: some RequestContext) throws -> Response { + Response(status: self.status) + } + } + router.get { _, _ -> String in + throw Custom404Error() + } + let app = Application(responder: router.buildResponder()) + + let text = "Test file contents" + let data = Data(text.utf8) + let fileURL = URL(fileURLWithPath: "index.html") + XCTAssertNoThrow(try data.write(to: fileURL)) + defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: fileURL)) } + + try await app.test(.router) { client in + try await client.execute(uri: "/", method: .get) { response in + XCTAssertEqual(String(buffer: response.body), text) + } + } + } + func testFolder() async throws { let router = Router() router.middlewares.add(FileMiddleware(".", searchForIndexHtml: false))