Skip to content

Cannot add a custom handler for HTTPExceptions with status_code=500 #2499

Discussion options

You must be logged in to vote

Apparently, this is by design. ServerErrorMiddleware (for 500 errors) and ExceptionMiddleware (for everything else) are separate so that the middleware stack can ben in this order

ServerErrorMiddleware
CustomMiddleware1
CustomMiddleware2
ExceptionMiddleware

I.E. Server errors get handled before any custom middleware runs but other HTTP exceptions get handled after any custom middleware runs, which makes sense.

https://www.starlette.io/middleware/#using-middleware

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@clickonben
Comment options

@zoola969
Comment options

@ccrims0n
Comment options

@clickonben
Comment options

@Kludex
Comment options

Kludex Oct 11, 2024
Maintainer Sponsor

Answer selected by clickonben
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants