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

max_well's avatar

Sentry in Nova no always propagating correctly

Hi,

is anyone using Nova and has also Sentry activated ( https://github.com/getsentry/sentry-laravel )?

Sentry works, when an exception in Laravel code happens, the sentry notification is triggered.

However within nova-based code I write, when an Exception is trigger, it seems it doesn't go through the app/Exception/Handler and thus doesn't go to sentry.

Any ideas?

thx!

0 likes
8 replies
devfrey's avatar
devfrey
Best Answer
Level 11

Nova uses its own exception handler Laravel\Nova\Exceptions\NovaExceptionHandler, which extends from the default. You could try overriding the registerExceptionHandler() method in your NovaServiceProvider to prevent Nova from binding its custom implementation:

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    /**
     * Register Nova's custom exception handler.
     *
     * @return void
     */
    protected function registerExceptionHandler()
    {
        // Don't register Nova's exception handler
    }
}

I'm not sure what the consequences would be, as this is not a documented feature and I haven't tested it.

Hope this solves your problem.

max_well's avatar

Awesome!

Now I've a trail to follow, thanks. Not sure why I couldn't figure it out by myself 🤷‍♀️

Btw, now I also understand why it only works within Novas part; at least that I got right, because of this:

        Nova::serving(function (ServingNova $event) {
            // …
            $this->registerExceptionHandler();
            // …
        });

Thanks!

max_well's avatar

So far my testing indicates that this works: override registerExceptionHandler and do nothing will leave the apps exception handler, with the Sentry behaviour, continue working.

Thanks!

sebsel's avatar

Please note there is a better way of doing this since november 2019: https://github.com/laravel/nova/pull/695

Edit for those without access to the Nova repo (you can link your Github on the Nova-site):

davidhemphill commented on Oct 31, 2019

This PR adds support for registering custom error reporting for Nova's exceptions. Currently Nova uses its own custom Exception handler which extends Laravel's default implementation, which does not use the application's custom report. The proposed changes allow the user to specify a callback to report Nova's errors to services like Sentry, Bugsnag, etc.

Nova::report(function ($exception) {
    // Send error report to 3rd party
});

meyer59 commented on Nov 13, 2019

What's the best place to put the Nova::report(...) method ?

jbrooksuk commented on Dec 2, 2019

You can place it in your NovaServiceProvider.

1stevengrant's avatar

I'm actually seeing the same thing and I've tried all methods. Going a whole 18 months without any error in Nova was good going I thought.

ricardolobo's avatar

This worked out for me:

I created a new App\Exceptions\NovaExceptionHandler that extends the original NovaExceptionHandler

namespace App\Exceptions;

use Laravel\Nova\Exceptions\NovaExceptionHandler as ExceptionHandler;
use Throwable;

class NovaExceptionHandler extends ExceptionHandler
{
    public function report(Throwable $e): void
    {
        if (app()->bound('sentry')) {
            app('sentry')->captureException($e);
        }

        parent::report($e);
    }
}

On NovaServiceProvider i added the following


use App\Exceptions\NovaExceptionHandler;

...

protected function registerExceptionHandler(): void
{
    app()->bind(ExceptionHandler::class, NovaExceptionHandler::class);
}

And now my app reports to sentry.

Using the recommended way https://nova.laravel.com/docs/4.0/installation.html#error-reporting does not work for me

1 like
Jelenik's avatar

@ricardolobo thank you, I made some naming changes in your example, but overall this finally works, so thanks!

Btw. I think in your example snippet in NovaServiceProvider you forgot to add one use statement:

use Laravel\Nova\Exceptions\NovaExceptionHandler as ExceptionHandler;

Please or to participate in this conversation.