Skip to content
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

Bug: MediaType not respected for ExceptionHandlerMiddleware #2024

Closed
1 of 4 tasks
JacobCoffee opened this issue Jul 20, 2023 · 0 comments · Fixed by #2131
Closed
1 of 4 tasks

Bug: MediaType not respected for ExceptionHandlerMiddleware #2024

JacobCoffee opened this issue Jul 20, 2023 · 0 comments · Fixed by #2131
Assignees
Labels
Bug 🐛 This is something that is not working as expected

Comments

@JacobCoffee
Copy link
Member

JacobCoffee commented Jul 20, 2023

Description

MediaType not respected when debug=False in litestar.middleware.exceptions.middleware.ExceptionHandlerMiddleware

#2011 We fixed the tests but this raises another issue of not respecting mediatype for exception response when not in debug - we shouldnt send back json in debug=False

Originally posted by @JacobCoffee in #2011 (comment)

URL to code causing the issue

https://github.com/JacobCoffee/litestar/blob/9d51278d17f3ef32390b9e9ae26cd312d16eab62/litestar/middleware/exceptions/middleware.py#L127

class ExceptionHandlerMiddleware:

MCVE

from litestar import Litestar, get
from litestar.response import Template


@get(path="/")
def invalid_path() -> Template:
    return Template(template_name="index.html", context={"ye": "yeeee"})

app = Litestar(route_handlers=[invalid_path], debug=False)

Steps to reproduce

1. Create app
2. Set debug to False
3. Raise an exception
4. In the response, when `debug = False` we receive back a `response.json()` but we should not because the mediatype is `text`

Screenshots

No response

Logs

No response

Litestar Version

2.0b3

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Funding

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
Fund with Polar
@JacobCoffee JacobCoffee added Bug 🐛 This is something that is not working as expected Triage Required 🏥 This requires triage labels Jul 20, 2023
@JacobCoffee JacobCoffee changed the title Bug: <title> Bug: MediaType not respected for ExceptionHandlerMiddleware Jul 20, 2023
@Goldziher Goldziher self-assigned this Jul 23, 2023
@Goldziher Goldziher removed the Triage Required 🏥 This requires triage label Jul 23, 2023
@Goldziher Goldziher linked a pull request Aug 6, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants