ErrorMiddleware
Captures all errors and transforms them into an internal server error HTTP response.
final class ErrorMiddleware
Captures all errors and transforms them into an internal server error HTTP response.
final class ErrorMiddleware
import Vapor
Vapor is a framework for building server applications, APIs and websites in Swift. It provides a safe, performant and scalable foundation for building large complex backends.
@preconcurrency protocol Middleware : Sendable
Middleware
is placed between the server and your router. It is capable of mutating both incoming requests and outgoing responses. Middleware
can choose to pass requests on to the next Middleware
in a chain, or they can short circuit and return a custom Response
if desired.
protocol Sendable
@preconcurrency init(_ closure: @escaping (Request, Error) -> (Response))
Create a new ErrorMiddleware
.
static func `default`(environment: Environment) -> ErrorMiddleware
Create a default ErrorMiddleware
. Logs errors to a Logger
based on Environment
and converts Error
to Response
based on conformance to AbortError
and Debuggable
.
func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response>
func makeResponder(chainingTo responder: Responder) -> Responder
Wraps a Responder
in a single Middleware
creating a new Responder
.