1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

report / render methods of ExceptionHandler never called

Discussão em 'Outras Linguagens' iniciado por Jean François Manatane, Novembro 8, 2024 às 06:32.

  1. laravel : 11.30.0

    I want to send an email each time my app throws an exception. So I added my code in the "report" method of ExceptionHandler but it appears the method is never executed.

    Here is my class :

    <?php

    namespace App\Exceptions;

    use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
    use Throwable;

    use App\Events\ExceptionOccurred;
    use Illuminate\Support\Facades\Log;


    class Handler extends ExceptionHandler
    {
    /**
    * A list of exception types with their corresponding custom log levels.
    *
    * @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
    */
    protected $levels = [
    //
    ];

    /**
    * A list of the exception types that are not reported.
    *
    * @var array<int, class-string<\Throwable>>
    */
    protected $dontReport = [
    //
    ];

    /**
    * A list of the inputs that are never flashed for validation exceptions.
    *
    * @var array<int, string>
    */
    protected $dontFlash = [
    'current_password',
    'password',
    'password_confirmation',
    ];

    /**
    * Report or log an exception.
    *
    * @param \Throwable $exception
    * @return void
    *
    * @throws \Exception
    */
    public function report(Throwable $exception) // NEVER EXECUTED
    {


    Log::info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");

    //
    event(new ExceptionOccurred($exception));


    parent::report($exception);
    }

    /**
    * Render an exception into an HTTP response.
    *
    * @param \Illuminate\Http\Request $request
    * @param \Throwable $exception
    * @return \Illuminate\Http\Response
    *
    * @throws \Throwable
    */
    public function render($request, Throwable $exception) // NEVER EXECUTED
    {

    Log::info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");


    return parent::render($request, $exception);
    }


    }


    Log::info works perfectly well, I use it everywhere in my app, so it is not a logging issue. I can even add a "exit();" it is the same.

    To make the exception, I added a type in a blade directive. The exception is displayed in the web browser.

    Any clue? I followed the doc, it seems I don't need to do anything else.

    Thanks

    Continue reading...

Compartilhe esta Página