Exceptions thrown inside middleware are not being logged

I'm throwing an exception like this:

use \Illuminate\Auth\Access\AuthorizationException;


class MyMiddleware {
   public function handle(Request $request, Closure $next, ...$guards)
    {
        ....
        throw new AuthorizationException();

    }
}

The exception is succcessfully thrown as expected but it doesn't hit the laravel.log file, nor it doesn't hit Exceptions/Handle.php

Any idea why?

Thanks.


Solution 1:

AuthorizationExceptions are not reported. One way to do what you want is to create a new exception. Something like this should work:

class Handler extends ExceptionHandler
{
    public function render($request, Exception $exception)
    {
       if ($exception instanceof AuthorizationException) {
           return (new CustomAuthorizationException)->render();
       }
    }
}