How to dump unhandled exceptions in routers in a central place for debugging / in development environment? #662
-
During debug or running in development environment, I need to log the details of unhandled exception thrown in router. I don't want to wrap every router in a
block. Is there a way to centrally dump all those errors for debugging? |
Beta Was this translation helpful? Give feedback.
Answered by
adam-fowler
Jan 24, 2025
Replies: 1 comment 1 reply
-
You could add a middleware to handle errors struct ErrorMiddleware<Context: RequestContext>: RouterMiddleware {
func handle(_ request: Request, context: Context, next: (Request, Context) async throws -> Response) async throws -> Response {
do {
return try await next(request, context)
} catch {
dump(error)
throw error
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
fyepi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could add a middleware to handle errors