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.
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:
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.
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 ?
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);
}