Problem/Motivation

If a developer enables the REST module, but not a formatter (such as HAL), the resulting error is fairly terse when hal_json is requested:

he website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException</em>: Not acceptable in <em class="placeholder">Drupal\Core\EventSubscriber\AcceptNegotiation406-&gt;onViewDetect406()</em> (line <em class="placeholder">37</em> of <em class="placeholder">core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php</em>).

Steps to reproduce

:

  • Enable the REST module
  • Grant anonymous users the restful get entity:node permission
  • Add a node
  • From the command line: curl http://d8.dev/node/1?_format=hal_json
  • See the exception

Proposed resolution

The thrown exception could at the very least include the requested format, instead of just Not acceptable.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

jhedstrom created an issue. See original summary.

jhedstrom’s picture

Status: Active » Needs review
StatusFileSize
new772 bytes

Status: Needs review » Needs work

The last submitted patch, 2: rest-dx-2558883-02.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new642 bytes
new1.38 KB

This should fix the test.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, I verified that the concatenated format which is user provided input does not pose a XSS risk. Looks like we are sanitizing those exception messages somewhere :-)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: rest-dx-2558883-04.patch, failed testing.

wim leers’s picture

Issue tags: +API-First Initiative
dawehner’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC

  • catch committed d8cf178 on
    Issue #2558883 by jhedstrom: Improve DX of formats that are requested...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.