ServiceUnavailableHttpException always uses text/plain headers

Created on 11 May 2021, about 3 years ago
Updated 20 December 2023, 6 months ago

Problem/Motivation

In both controllers and REST resource plugins, throwing \Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException will cause the response to be in plain text. This goes as far as ignoring the ?_format=json query parameter and a default format set in a routing file.

Steps to reproduce

  1. Create a simple module and controller.
  2. Throw ServiceUnavailableHttpException in the controller.
  3. Make a HTTP GET request (browser, curl, shouldn't matter what you use). The response Content-Type header will be text/plain.

I attached a small custom module to demonstrate. Install it, and HTTP GET request:

  • /service-unavailable/400
  • /service-unavailable/403
  • /service-unavailable/503

I set _format: json in the routing file. That does not solve the problem, nor does using the ?_format=json URL query version.

Proposed resolution

Use the expected / requested content type for the response, as with other HTTP exceptions.

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 6 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States alexdmccabe Orlando, FL, US / Seminole lands

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Can you advise what Accept header you're sending with the request?

    Looking at \Drupal\serialization\EventSubscriber\DefaultExceptionSubscriber::on4xx it looks like it mirrors back the header based on that.

  • πŸ‡ΊπŸ‡ΈUnited States alexdmccabe Orlando, FL, US / Seminole lands

    That's maybe not the best experience since support for the Accept header was removed and replaced with the _format query parameter. It should probably mirror _format back instead of an otherwise unused header, shouldn't it?

    As for what header I'm sending, I don't know, I opened this issue a while ago. I'll try to dig up the original circumstances.

  • Status changed to Active 6 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    support for the Accept header was removed and replaced with the _format query parameter. It should probably mirror _format back instead

    Yeah that's a fair point

Production build 0.69.0 2024