function RouterTestEarlyExceptionSubscriber::onKernelRequest

Same name in other branches
  1. 11.x core/modules/system/tests/modules/router_test_directory/src/RouterTestEarlyExceptionSubscriber.php \Drupal\router_test\RouterTestEarlyExceptionSubscriber::onKernelRequest()

Throw an exception, which will trigger exception-handling subscribers.

See DefaultExceptionHtmlSubscriber.

File

core/modules/system/tests/modules/router_test_directory/src/RouterTestEarlyExceptionSubscriber.php, line 23

Class

RouterTestEarlyExceptionSubscriber
Event subscribers for exceptions thrown in early kernel middleware.

Namespace

Drupal\router_test

Code

public function onKernelRequest(RequestEvent $event) : void {
    if ($event->isMainRequest() && $event->getRequest()->headers
        ->get('Authorization') === 'Bearer invalid') {
        throw new HttpException(Response::HTTP_UNAUTHORIZED, 'This is a common exception during authentication.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.