Problem/Motivation
JSON:API module provides a number of customized normalizers for exception types which return a JSON pointer to the offending data in the request object. E.g., EntityAccessDeniedHttpExceptionNormalizer and UnprocessableHttpEntityExceptionNormalizer.
In my case, I wish to control access to particular Search API fields (I'm revealing them using jsonapi_search_api) and return a 402 Payment Required response to hint the client side to tell the user which fields are premium/access controlled.
Because of the class structures of Cacheable*HttpException and their underlying Symfony HTTP exception classes, there's no way to use one of the existing exception types b/c I can't override the status code, and they expect a certain shape of the underlying exception to create the JSON pointer data in the source error response property. Additionally, my source values are parameter, since they're specified in the query string.
I can create my own CacheablePaymentRequiredHttpException class, which is normalized by the basic HttpExceptionNormalizer, but it has no built-in method to include source data in the resulting normalization/json:api error response.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3302299-nr-bot.txt | 2.54 KB | needs-review-queue-bot |
Issue fork drupal-3302299
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
bradjones1Comment #4
bradjones1I think this would also be fine to kill #3302301: Specifying `error.source.[line,file]` in HttpExceptionNormalizer violates json:api spec at same time since we are fixing up the
sourceproperty.Whipped this up quickly while working on our product but if this looks good to maintainers, easy to add one (which would also demonstrate how to add your own exception type in userland...)
Comment #5
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #7
bradjones1Error is a bit hidden in the GitLab CI output, but here it is: