Skip to content

Bug: exception_handlers are not applied when debug flag is False #3581

Answered by TheZwieback
TheZwieback asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks, I see my mistake. I assumed the LitestarException map would catch all exceptions for some reason. I checked the code and if I use the correct error mapping it works. Here is the working example for completeness:

from litestar.exceptions import HTTPException
from litestar.status_codes import HTTP_500_INTERNAL_SERVER_ERROR
from litestar import Request, Response, Litestar, post

import logging


def exception_handler(_: Request, exc: Exception) -> Response:
    if isinstance(exc, HTTPException) and exc.status_code != HTTP_500_INTERNAL_SERVER_ERROR:
        status_code = getattr(exc, "status_code", HTTP_500_INTERNAL_SERVER_ERROR)
        detail = getattr(exc, "detail", "")

        re…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Alc-Alc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Bug 🐛 This is something that is not working as expected
2 participants
Converted from issue

This discussion was converted from issue #3579 on June 18, 2024 08:20.