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

opheliadesign's avatar

Don't Report HttpException::class, Raven/Sentry

Hi everyone,

I'm using Raven/Sentry to catch errors from both a Lumen 5.1 and Laravel 5.1 app. I'm getting flooded with NotFoundHttpException (and other exceptions similar to that, such as 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException'). I am using rcrowe/raven to capture Log::error() in my Handler.php, which in turn sends the exception to Sentry.

No matter what I've tried I cannot get these Not Found exceptions to stop. What am I missing? Here is my Handler.php, I've tried a variety of different things in $dontReport, this is the current state:

<?php namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Session\TokenMismatchException;
use Log;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
        'Symfony\Component\HttpKernel\Exception\NotFoundHttpException',
        HttpException::class,
    ];

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception $e
     * @return void
     */
    public function report(Exception $e)
    {
        Log::error($e);
//        return parent::report($e);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Exception $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
        if ($e instanceof TokenMismatchException) {
            //Redirect to login form if session expires
            return redirect($request->fullUrl())->with('errors',
                ["The login form has expired, please try again. In the future, reload the login page if it has been open for several hours."]);
        }
        return parent::render($request, $e);
    }

}

0 likes
8 replies
opheliadesign's avatar

Anyone? My phone is going off endlessly because of these... and I'm thinking it will begin cutting into the limit

danwall's avatar

Looks like you've commented out return parent::report($e);, which contains the logic required to handle what's in the $dontReport array.

Furthermore, you haven't imported HttpException so when you run ::class on it, it won't know what class name to get.

opheliadesign's avatar

@danwall this is the only way I can seem to get this to work..

protected $dontReport = [
        HttpException::class,
        NotFoundHttpException::class
    ];

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception $e
     * @return void
     */
    public function report(Exception $e)
    {
//        Log::error($e);
        if (!$e instanceof NotFoundHttpException && !$e instanceof HttpException) {
            $client = new Raven_Client('DSN');
            $client->captureException($e);
        }
        return parent::report($e);
    }

So I guess $dontReport basically just means $dontSaveToLog because it'll still fire whatever is in $report, or so it would seem.

jonathanc's avatar

I ended up having the same issue as the posters above.

I did a hybrid solution of opheliadesign's answer so that the array needs to be maintained in only one place ($dontReport)

Example:

use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

protected $dontReport = [
    HttpException::class,
    NotFoundHttpException::class,
    ModelNotFoundException::class
];

public function report(Exception $e)
{
    if (!in_array(get_class($e), $this->dontReport)) {
    // do whatever
    }
    parent::report($e);
}

Hope this helps!

1 like
Dara Dolan's avatar

Would the following work also?

public function report(Exception $e)
{
    if ($this->shouldReport($e)) {
    // do whatever
    }
    return parent::report($e);
}

Please or to participate in this conversation.