From ed9aec65dc355684dde2df267df490e964d3131c Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Thu, 30 May 2024 13:53:11 +0100 Subject: [PATCH] Fix Error Middleware docs (#981) [`ErrorMiddleware` is not the only middleware added by default](https://github.com/vapor/vapor/blob/cc98361cbec22757a89a9717836293f215a0f67d/Sources/Vapor/Middleware/Application%2BMiddleware.swift#L8). This PR updates that assertion and the replacement instructions to re-introduce `RouteLoggingMiddleware`. --- docs/basics/errors.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/basics/errors.md b/docs/basics/errors.md index 6e9d70c5..ca3ddcdc 100644 --- a/docs/basics/errors.md +++ b/docs/basics/errors.md @@ -183,13 +183,14 @@ StackTrace.isCaptureEnabled = true ## Error Middleware -`ErrorMiddleware` is the only middleware added to your application by default. This middleware converts Swift errors that have been thrown or returned by your route handlers into HTTP responses. Without this middleware, errors thrown will result in the connection being closed without a response. +`ErrorMiddleware` is one of the only two middlewares added to your application by default. This middleware converts Swift errors that have been thrown or returned by your route handlers into HTTP responses. Without this middleware, errors thrown will result in the connection being closed without a response. -To customize error handling beyond what `AbortError` and `DebuggableError` provide, you can replace `ErrorMiddleware` with your own error handling logic. To do this, first remove the default error middleware by setting `app.middleware` to an empty configuration. Then, add your own error handling middleware as the first middleware to your application. +To customize error handling beyond what `AbortError` and `DebuggableError` provide, you can replace `ErrorMiddleware` with your own error handling logic. To do this, first remove the default error middleware by manually initializing `app.middleware`. Then, add your own error handling middleware as the first middleware to your application. ```swift -// Remove all existing middleware. +// Clear all default middleware (then, add back route logging) app.middleware = .init() +app.middleware.use(RouteLoggingMiddleware(logLevel: .info)) // Add custom error handling middleware first. app.middleware.use(MyErrorMiddleware()) ```