Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Matthias1984's avatar

Get notified on 404

I'm using the implementation of https://laravel-news.com/email-on-error-exceptions in order to get exceptions of my production server by mail. This works perfectly fine.

Nevertheless on 404 errors (Page not found.) this mechanism does not work. Laravel does show me a 404 error screen but I don't get the real exception. In /app/Exceptions/Handler.php the $dontReport array is empty and in its parent class /vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php the internal don't reports are commented out (just for testing):

protected $internalDontReport = [
	// AuthenticationException::class,
	// AuthorizationException::class,
	// HttpException::class,
	// HttpResponseException::class,
	// ModelNotFoundException::class,
	// SuspiciousOperationException::class,
	// TokenMismatchException::class,
	// ValidationException::class,
];

How is it possible to render the actual HttpExceptions? I would like to get an info if any route does not work (independent if it's just a typo or a real missing route...).

0 likes
2 replies
Oussama.tn's avatar
Level 10

Hi!

Inside your app/Exceptions/Handler.php

Add this function:

    private function isNotFoundException($exception)
    {
        return $exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
            || $exception instanceof \Illuminate\Database\Eloquent\ModelNotFoundException;
    }

Then you can use it like this:

    public function report(Throwable $exception)
    {
        if ($this->isNotFoundException($exception)) {
            // Send you mail here !!! :)
        }

        parent::report($exception);
    }
Matthias1984's avatar

Thank you very much! Works perfectly as expected :)

1 like

Please or to participate in this conversation.