Skip to content

Commit 11c1279

Browse files
authored
Merge pull request #1 from vapor/main
Fix Error Middleware docs (vapor#981)
2 parents e766c66 + ed9aec6 commit 11c1279

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)