Skip to content

How to dump unhandled exceptions in routers in a central place for debugging / in development environment? #662

Answered by adam-fowler
fyepi asked this question in Q&A
Discussion options

You must be logged in to vote

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
        }
    }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fyepi
Comment options

Answer selected by fyepi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants