diff --git a/jsonapi.services.yml b/jsonapi.services.yml index 4b65c59..09e21d3 100644 --- a/jsonapi.services.yml +++ b/jsonapi.services.yml @@ -102,9 +102,9 @@ services: jsonapi.http_middleware.format_setter: class: Drupal\jsonapi\StackMiddleware\FormatSetter tags: - # Set priority to 399 so it happens right after the format in the ?_format - # has been set in the request. That is set to 400. - - { name: http_middleware, priority: 399, responder: true } + # Set priority to 201 so it happens right before the page cache middleware + # has the opportunity to respond. http_middleware.page_cache is 200. + - { name: http_middleware, priority: 201, responder: true } logger.channel.jsonapi: parent: logger.channel_base diff --git a/src/EventSubscriber/DefaultExceptionSubscriber.php b/src/EventSubscriber/DefaultExceptionSubscriber.php index ef57d37..cb85137 100644 --- a/src/EventSubscriber/DefaultExceptionSubscriber.php +++ b/src/EventSubscriber/DefaultExceptionSubscriber.php @@ -3,6 +3,7 @@ namespace Drupal\jsonapi\EventSubscriber; use Drupal\serialization\EventSubscriber\DefaultExceptionSubscriber as SerializationDefaultExceptionSubscriber; +use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; @@ -69,10 +70,11 @@ class DefaultExceptionSubscriber extends SerializationDefaultExceptionSubscriber * TRUE if it needs to be formated using JSON API. FALSE otherwise. */ protected function isJsonApiFormatted(Request $request) { + $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT); $format = $request->getRequestFormat(); // The JSON API format is supported if the format is explicitly set or the // request is for a known JSON API route. - return $format == 'api_json' || $request->attributes->get('_is_jsonapi'); + return $format == 'api_json' || ($route && $route->getOption('_is_jsonapi')); } }