Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 16 |
| ExceptionJsonSubscriber | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
42 | |
0.00% |
0 / 16 |
| getHandledFormats | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| getPriority | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
| on403 | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| on404 | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| on405 | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| on406 | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\Core\EventSubscriber\ExceptionJsonSubscriber. | |
| */ | |
| namespace Drupal\Core\EventSubscriber; | |
| use Symfony\Component\HttpFoundation\JsonResponse; | |
| use Symfony\Component\HttpFoundation\Response; | |
| use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; | |
| /** | |
| * Default handling for JSON errors. | |
| */ | |
| class ExceptionJsonSubscriber extends HttpExceptionSubscriberBase { | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| protected function getHandledFormats() { | |
| return ['json']; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| protected static function getPriority() { | |
| // This will fire after the most common HTML handler, since HTML requests | |
| // are still more common than JSON requests. | |
| return -75; | |
| } | |
| /** | |
| * Handles a 403 error for JSON. | |
| * | |
| * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event | |
| * The event to process. | |
| */ | |
| public function on403(GetResponseForExceptionEvent $event) { | |
| $response = new JsonResponse(array('message' => $event->getException()->getMessage()), Response::HTTP_FORBIDDEN); | |
| $event->setResponse($response); | |
| } | |
| /** | |
| * Handles a 404 error for JSON. | |
| * | |
| * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event | |
| * The event to process. | |
| */ | |
| public function on404(GetResponseForExceptionEvent $event) { | |
| $response = new JsonResponse(array('message' => $event->getException()->getMessage()), Response::HTTP_NOT_FOUND); | |
| $event->setResponse($response); | |
| } | |
| /** | |
| * Handles a 405 error for JSON. | |
| * | |
| * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event | |
| * The event to process. | |
| */ | |
| public function on405(GetResponseForExceptionEvent $event) { | |
| $response = new JsonResponse(array('message' => $event->getException()->getMessage()), Response::HTTP_METHOD_NOT_ALLOWED); | |
| $event->setResponse($response); | |
| } | |
| /** | |
| * Handles a 406 error for JSON. | |
| * | |
| * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event | |
| * The event to process. | |
| */ | |
| public function on406(GetResponseForExceptionEvent $event) { | |
| $response = new JsonResponse(['message' => $event->getException()->getMessage()], Response::HTTP_NOT_ACCEPTABLE); | |
| $event->setResponse($response); | |
| } | |
| } |