PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 21, 2022

[FIXED] Exceptions thrown inside middleware are not being logged

 February 21, 2022     laravel     No comments   

Issue

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

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();
       }
    }
}


Answered By - mankowitz
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing