-
-
Notifications
You must be signed in to change notification settings - Fork 930
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom error handler not called by ServerErrorMiddleware
in debug mode
#1802
Comments
yes, it would be very much appreciated ;) |
|
It doesn't make sense to me for |
Right, that was my rationale here too. https://docs.djangoproject.com/en/4.0/ref/views/#the-500-server-error-view |
@alex-oleshkevich Are you strong on this, or can we close this issue and associated PR? @tomchristie Would you mind inviting @alex-oleshkevich to the organization? |
@Kludex I think you can close it. However, I still believe that this is a good add-on to the library. The current implementation steals too much control from the developer. |
that would be nice to have yes |
Flask has the same behavior as well: https://flask.palletsprojects.com/en/2.2.x/errorhandling/#unhandled-exceptions Why would Starlette do something different than those two? |
well 2 reasons, one is that Starlette debugger is very "minimal" compared to what Django and Flask ships by default. Starception is definitely nicer in every possible way than this default, even superior imho to what Flask provides. There would be no case if Starlette's debugger would be on par with it. Starlette wants to keep the maintained codebase small, so "plugins" like this should be usable I think |
Correct me if I'm wrong, but... It's usable, and @alex-oleshkevich is not blocked. The package can document for users to do something like: if debug:
middleware.append([DebugMiddleware]) Or... Change the
If this gets in, then it will be even minimal, as I don't see why would someone use it anymore. I think the discussion should be different in this case: "is the debug flag useful?". |
yes it's usable, but (don't quote me on this I may remember the stuff badly) it is not the outer layer of the middleware stack as the exception layer should be iirc, so exceptions raised after will be rendered using the starlette debugger template and not the starception one. #1386 dismissed it, the current debugger in starlette serves no purpose to me in its current form. |
Can't the package recommend something like: middleware = []
if os.getenv("DEBUG"):
middleware.append([DebugMiddleware])
app = Starlette(middleware=middleware) # Do not use the `debug` flag! Instead of: middleware = [DebugMiddleware]
app = Starlette(middleware=middleware, debug=True) |
Sure, but this looks like a hack IMO, the perfect solution is to re-use existing functionality of exception handlers or add a new constructor argument to Starlette to override exception handler in
This is bad advice as application may depend on that flag in different ways. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
ServerErrorMiddleware
ignoreshandler
argument when app is running in debug mode. Instead, it always calls the default one.This causes us to do workarounds like reimplementing
ServerErrorMiddleware
on our own just to use an alternate exception handler in debug mode. Though intuitively, you expectexception_handlers
for that purpose.Would it make sense to always call a configured handler when available, and ignore the default one?
A possible solution can look like this:
Let me know if I can PR it.
The text was updated successfully, but these errors were encountered: