Skip to content

Conversation

@mgorven
Copy link
Contributor

@mgorven mgorven commented Oct 28, 2025

Description

HTTP exceptions are returned as a plain text message, but various HTTP framework views default to text/html as the Content-Type or don't set it at all. Set the Content-Type to text/plain so that these are displayed correctly.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

Set the Content-Type header to text/plain for Quart exception responses

Bug Fixes:

  • Ensure exception responses in Quart views are returned with Content-Type "text/plain" instead of the default
  • Add explicit content_type="text/plain" to Response for exceptions

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 28, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts Quart exception responses to explicitly use "text/plain" for the Content-Type header instead of the default "text/html" by updating the dispatch_request implementation.

File-Level Changes

Change Details Files
Ensure exception responses use text/plain content type
  • Added content_type="text/plain" to the Response constructor for exception handling in dispatch_request
strawberry/quart/views.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@botberry
Copy link
Member

botberry commented Oct 28, 2025

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Set Content-Type to text/plain for exceptions so that these are displayed
correctly.

Here's the tweet text:

🆕 Release (next) is out! Thanks to Michael Gorven for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

Fixed incorrect Content-Type header in Quart's HTTPException responses by explicitly setting content_type="text/plain".

  • Issue: Quart's Response class defaults to text/html Content-Type, causing plain text error messages to be served with the wrong MIME type
  • Fix: Added content_type="text/plain" parameter when creating Response objects for HTTPException handlers
  • Impact: Error messages now display correctly in browsers and API clients instead of being interpreted as HTML
  • Consistency: FastAPI already uses PlainTextResponse for similar exceptions; this brings Quart in line with that pattern

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is a simple one-line fix that explicitly sets the correct Content-Type header for error responses. The fix aligns with how other frameworks (FastAPI) handle the same scenario, addresses a real bug where error messages were served with the wrong MIME type, and has no side effects on existing functionality.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
strawberry/quart/views.py 5/5 Added content_type="text/plain" to HTTPException Response to fix incorrect Content-Type header (was defaulting to text/html)

Sequence Diagram

sequenceDiagram
    participant Client
    participant GraphQLView
    participant AsyncBaseHTTPView
    participant QuartResponse

    Client->>GraphQLView: HTTP Request (GET/POST/WebSocket)
    GraphQLView->>GraphQLView: dispatch_request()
    
    alt Valid Request
        GraphQLView->>AsyncBaseHTTPView: run(request)
        AsyncBaseHTTPView->>AsyncBaseHTTPView: execute_operation()
        AsyncBaseHTTPView-->>GraphQLView: GraphQLHTTPResponse
        GraphQLView->>QuartResponse: Response(data, content_type="application/json")
        QuartResponse-->>Client: JSON Response
    else HTTPException (Invalid Request)
        AsyncBaseHTTPView->>AsyncBaseHTTPView: parse/validate request
        AsyncBaseHTTPView-->>GraphQLView: raise HTTPException(status, reason)
        GraphQLView->>QuartResponse: Response(reason, status, content_type="text/plain")
        Note over QuartResponse: Fix: Added content_type="text/plain"<br/>Previously defaulted to "text/html"
        QuartResponse-->>Client: Plain Text Error Response
    end
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@patrick91
Copy link
Member

Looks good to me! @mgorven would you mind adding a test and a RELEASE.md file? 😊

HTTP exceptions are returned as a plain text message, but various HTTP
framework views default to `text/html` as the Content-Type or don't set
it at all. Set the Content-Type to `text/plain` so that these are
displayed correctly.
@mgorven mgorven changed the title Fix Content-Type for Quart exceptions Fix Content-Type for HTTP exceptions Oct 29, 2025
@mgorven
Copy link
Contributor Author

mgorven commented Oct 29, 2025

Looks good to me! @mgorven would you mind adding a test and a RELEASE.md file? 😊

Done. I also fixed the other HTTP framework views.

@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.42%. Comparing base (2239707) to head (1730f6e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4037   +/-   ##
=======================================
  Coverage   94.42%   94.42%           
=======================================
  Files         536      536           
  Lines       35002    35008    +6     
  Branches     1836     1836           
=======================================
+ Hits        33051    33057    +6     
  Misses       1656     1656           
  Partials      295      295           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 29, 2025

CodSpeed Performance Report

Merging #4037 will not alter performance

Comparing mgorven:quart-errors (1730f6e) with main (2239707)

Summary

✅ 28 untouched

Copy link
Collaborator

@Ckk3 Ckk3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me too!
Thanks for you contribuition @mgorven ❤️

About the pre-commit error we are getting in the CI, it is something that I fixed in this commit.
No need to add this in your code, I'm just talking about it so we can move foward knowing that this error has nothing related to your PR ☺️

@mgorven
Copy link
Contributor Author

mgorven commented Nov 7, 2025

What's left to get this merged?

Copy link
Member

@bellini666 bellini666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking some time @mgorven . Looks good :)

I merged main here to fix pre-commit issues. Just waiting for tests to pass and I'll merge it :)

@bellini666 bellini666 merged commit 2437857 into strawberry-graphql:main Nov 21, 2025
82 checks passed
@botberry
Copy link
Member

Thanks for contributing to Strawberry! 🎉 You've been invited to join
the Strawberry GraphQL organisation 😊

You can also request a free sticker by filling this form: https://forms.gle/dmnfQUPoY5gZbVT67

And don't forget to join our discord server: https://strawberry.rocks/discord 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants