class ExceptionJsonSubscriber in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/EventSubscriber/ExceptionJsonSubscriber.php \Drupal\Core\EventSubscriber\ExceptionJsonSubscriber
Default handling for JSON errors.
Hierarchy
- class \Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase implements EventSubscriberInterface
- class \Drupal\Core\EventSubscriber\ExceptionJsonSubscriber
Expanded class hierarchy of ExceptionJsonSubscriber
1 file declares its use of ExceptionJsonSubscriber
- ExceptionHalJsonSubscriber.php in core/
modules/ hal/ src/ EventSubscriber/ ExceptionHalJsonSubscriber.php - Contains \Drupal\hal\EventSubscriber\ExceptionHalJsonSubscriber.
1 string reference to 'ExceptionJsonSubscriber'
- core.services.yml in core/
core.services.yml - core/core.services.yml
2 services use ExceptionJsonSubscriber
File
- core/
lib/ Drupal/ Core/ EventSubscriber/ ExceptionJsonSubscriber.php, line 17 - Contains \Drupal\Core\EventSubscriber\ExceptionJsonSubscriber.
Namespace
Drupal\Core\EventSubscriberView source
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExceptionJsonSubscriber:: |
protected | function |
Specifies the request formats this subscriber will respond to. Overrides HttpExceptionSubscriberBase:: |
1 |
ExceptionJsonSubscriber:: |
protected static | function |
Specifies the priority of all listeners in this class. Overrides HttpExceptionSubscriberBase:: |
|
ExceptionJsonSubscriber:: |
public | function | Handles a 403 error for JSON. | |
ExceptionJsonSubscriber:: |
public | function | Handles a 404 error for JSON. | |
ExceptionJsonSubscriber:: |
public | function | Handles a 405 error for JSON. | |
ExceptionJsonSubscriber:: |
public | function | Handles a 406 error for JSON. | |
HttpExceptionSubscriberBase:: |
public static | function |
Registers the methods in this class that should be listeners. Overrides EventSubscriberInterface:: |
|
HttpExceptionSubscriberBase:: |
public | function | Handles errors for this subscriber. |