Skip to content

Commit ed9aec6

Browse files
authored
Fix Error Middleware docs (vapor#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`.
1 parent 0005a29 commit ed9aec6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

docs/basics/errors.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,14 @@ StackTrace.isCaptureEnabled = true
183183

184184
## Error Middleware
185185

186-
`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.
186+
`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.
187187

188-
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.
188+
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.
189189

190190
```swift
191-
// Remove all existing middleware.
191+
// Clear all default middleware (then, add back route logging)
192192
app.middleware = .init()
193+
app.middleware.use(RouteLoggingMiddleware(logLevel: .info))
193194
// Add custom error handling middleware first.
194195
app.middleware.use(MyErrorMiddleware())
195196
```

0 commit comments

Comments
 (0)