Problem/Motivation

Result:

The website encountered an unexpected error. Please try again later.undefined</br>undefined</br>undefined<em class="placeholder">Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException</em>: Not acceptable in undefined<em class="placeholder">Drupal\Core\EventSubscriber\AcceptNegotiation406-&gt;onViewDetect406()</em> (line undefined<em class="placeholder">37</em> of undefined<em class="placeholder">core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php</em>). undefined<pre class="backtrace">Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher-&gt;dispatch(&#039;kernel.view&#039;, Object)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache-&gt;fetch(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache-&gt;lookup(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1)
Drupal\Core\DrupalKernel-&gt;handle(Object)
</pre>

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Title: Enable rest without hal_json and accessing ?_format=hal_json results in a 406 » Enable rest without hal_json and accessing ?_format=hal_json results in a 500
clemens.tolboom’s picture

[edit]It's even worse. Visiting http://drupal.d8/node/1?_format=whatever throws the same exception. (doh)[/edit]

There should not be a PHP exception induced by bad formats.

damiankloip’s picture

This returns a 406 response for me, which I think is fine. I just think the problem might be that we have the trace there?

damiankloip’s picture

So the problem is that DefaultExceptionSubscriber is handling this I guess. Because the exception implements HttpExceptionInterface the correct response code is set, but the trace is always added to the response content.

damiankloip’s picture

It's rough, but maybe we need to do something like this for formats we don't know about?

dawehner’s picture

Title: Enable rest without hal_json and accessing ?_format=hal_json results in a 500 » Accessing a non existing format results in a 500
Wim Leers’s picture

Status: Active » Needs review

NR for #6.

dawehner’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This is looking great but I guess we better have some kind of integration test coverage

dawehner’s picture

Working on the tests now.

dawehner’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1.74 KB
1.52 KB

Here is one. Sadly shit actually just works if you test it.

dawehner’s picture

Here is the test.

dawehner’s picture

Priority: Normal » Major

Being able to trigger 500s easily on any page is IMHO major for me.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +DX (Developer Experience), +API-First Initiative
damiankloip’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, small thing.

+++ b/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php
@@ -173,11 +187,18 @@ protected function onJson(GetResponseForExceptionEvent $event) {
     // If it's an unrecognized format, assume HTML.

I guess we need to change that comment now too.

Otherwise, looks like some nice changes to my patch. Thanks! After that, agree it is RTBC.

damiankloip’s picture

Also, as with the example in the summary. It is not immediately clear that any request for a non-existent format fails. hal_json *can* exist. E.g. the same outcome would occur with a request like http://d8-dev/node/1?_format=bananas Not sure if the tests should reflect that too? As it's easy to get confused as to why hal_json wouldn't be a valid format IMO.

Wim Leers’s picture

Assigned: Unassigned » Wim Leers

+1 for #16.

I'll address the feedback in a reroll.

Wim Leers’s picture

Assigned: Wim Leers » Unassigned
Status: Needs work » Needs review
FileSize
3.63 KB
1.9 KB
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

+1. Works for me

dawehner’s picture

Issue summary: View changes

  • catch committed 4c643ff on
    Issue #2594777 by dawehner, Wim Leers, damiankloip: Accessing a non...
catch’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Committed/pushed to 8.1.x, thanks!

For 8.0.x, we probably need to explicitly @internal the new method and underscore prefix it, so moving to 'to be ported' for that.

therealssj’s picture

A Patch for 8.0.x in accordance with changes mentioned in #22

therealssj’s picture

Status: Patch (to be ported) » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: 2594777-23.patch, failed testing.

therealssj’s picture

Status: Needs work » Needs review
FileSize
3.66 KB
1.85 KB

Patch for 8.x
Tested.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Well, I'm not sure whether we still care about 8.0.x at that point, but sure, this change looks right.

clemens.tolboom’s picture

This does not work for 8.2.x as I still get a 500

The exception is definitely not

// core/lib/Drupal/Core/EventSubscriber/DefaultExceptionSubscriber.php:194
if ($exception instanceof HttpExceptionInterface) {
therealssj’s picture

I just tried to reproduce this is 8.2.x and i don't see any issue.
@clemens.tolboom could you tell the steps you followed to get that 500?

dawehner’s picture

@clemens.tolboom
Please open up a new issue ...

clemens.tolboom’s picture

Sorry for wasting your time. I had a view not liking the format. That's another issue (I hope)

alexpott’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Reviewed & tested by the community » Closed (fixed)

8.0.x has entered it's last RC so this is no longer eligible for commit.