Utility base class for exception subscribers.
A subscriber may extend this class and implement getHandledFormats() to indicate which request formats it will respond to. Then implement an on*() method for any error code (HTTP response code) that should be handled. For example, to handle 404 Not Found messages add a method:
public function on404(GetResponseForExceptionEvent $event) {}
That method should then call $event->setResponse() to set the response object for the exception. Alternatively, it may opt not to do so and then other listeners will have the opportunity to handle the exception.
Note: Core provides several important exception listeners by default. In most cases, setting the priority of a contrib listener to the default of 0 will do what you expect and handle the exceptions you'd expect it to handle. If a custom priority is set, be aware of the following core-registered listeners.
All other core-provided exception handlers have negative priorities so most module-provided listeners will naturally take precedence over them.
Name | Modifiers | Type | Description |
---|---|---|---|
HttpExceptionSubscriberBase::getHandledFormats | abstract protected | function | Specifies the request formats this subscriber will respond to. |
HttpExceptionSubscriberBase::getPriority | protected static | function | Specifies the priority of all listeners in this class. |
HttpExceptionSubscriberBase::getSubscribedEvents | public static | function | Registers the methods in this class that should be listeners. Overrides EventSubscriberInterface::getSubscribedEvents |
HttpExceptionSubscriberBase::onException | public | function | Handles errors for this subscriber. |
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!EventSubscriber!HttpExceptionSubscriberBase.php/class/HttpExceptionSubscriberBase/8.1.x