Vapor Documentation Beta

Class Error​Middleware

public final class ErrorMiddleware: Middleware

Captures all errors and transforms them into an internal server error HTTP response.

%3 ErrorMiddleware ErrorMiddleware Middleware Middleware ErrorMiddleware->Middleware

Conforms To


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.



public init(_ closure: @escaping (Request, Error) -> (Response))

Create a new ErrorMiddleware.


closure @escaping (Request, Error) -> (Response)

Error-handling closure. Converts Error to Response.



public 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.


environment Environment

The environment to respect when presenting errors.


public func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response>

See Middleware.