JSON and other serialization formats now handle non-4xx exceptions

Created on 21 August 2022, almost 2 years ago
Updated 15 June 2024, 13 days ago

Problem/Motivation

Despite claims to the contrary in various code snippets in the exception handling system, non-HTML requests to Drupal aren't that rare, anymore. Modules such as JSON-RPC and Simple OAuth work almost entirely over a JSON, for instance, but exceptions thrown while handling their routes many times come back as HTML.

I am working on getting exceptions thrown during Simple OAuth's processing (e.g., with an extension grant type) and even after adding a default _format: 'json' notation in the route's requirements, I still get HTML error pages.

This is because ExceptionJsonSubscriber and Serialization module's DefaultExceptionSubscriber (which overrides the former, if the module is enabled) both only explicitly handle 4xx.

JSON:API has its own DefaultExceptionSubscriber implementation which does also handle 5xx. I propose extracting this logic to the above two other handlers, so we can get mostly automatic exception handling on non-HTML routes.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

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.

  • Status changed to Needs review about 1 month ago
  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

    Rebased and cleaned up for 11.x. I think this could be considered a bug, or a task, but definitely a DX improvement for decoupled environments.

  • Status changed to RTBC about 1 month ago
  • πŸ‡³πŸ‡±Netherlands bbrala Netherlands

    It looks good, tests are available so removing tag.

    Added a changerecord, since that was still needed.

    This chnage is awesome, and upping the game a little more for API users.

  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand
  • Status changed to Needs work 26 days ago
  • The Needs Review Queue Bot β†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to RTBC 22 days ago
  • πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

    Coding standards bumped, keeping RTBC.

  • Status changed to Needs work 13 days ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Added a couple of comments to the MR.

Production build 0.69.0 2024