4.121.0 - The RouteNotFound that is used when the router finds nothing is now public
What's Changed
The RouteNotFound that is used when the router finds nothing is now public by @fizker in #3326
When no routes match the current request,
DefaultResponderthrows theRouteNotFounderror.This PR makes that error public, allowing any middleware to handle that specific scenario.
Unlike the CatchAll route
**, a middleware catching theRouteNotFoundworks across all HTTP methods automatically.This would be used in a middleware like so:
public struct CatchAllMiddleware: AsyncMiddleware { public func respond(to request: Request, chainingTo next: any AsyncResponder) async throws -> Response { do { return try await next.respond(to: request) } catch is RouteNotFound { // No route was found, so this would normally result in a 404. // We can now handle this like any other request. // Or we can make treat it like an ErrorMiddleware where we // log purposeful 404s different than `RouteNotFound` 404s. ... } } }
This patch was released by @0xTim
Full Changelog: https://github.com/vapor/vapor/compare/4.120.0...4.121.0