How to throw an exception to users in drupal

With custom development come a lot of entry points for users. This snippet throws access denied for users that are too curious on some paths.

use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

if(!$contest->isActive()) {
  throw new AccessDeniedHttpException();
}

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!