Home > Mobile >  Exceptions thrown inside middleware are not being logged
Exceptions thrown inside middleware are not being logged

Time:01-18

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.

CodePudding user response:

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();
       }
    }
}
  •  Tags:  
  • Related