Skip to content

Commit d8a09b8

Browse files
authored
Add exception handler (#398)
* Add exception handler to report exceptions in console * Fix styling --------- Co-authored-by: simonhamp <[email protected]>
1 parent 1cb1c56 commit d8a09b8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Exceptions/Handler.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Native\Laravel\Exceptions;
4+
5+
class Handler extends \Illuminate\Foundation\Exceptions\Handler
6+
{
7+
protected $internalDontReport = [];
8+
9+
public function register(): void
10+
{
11+
$this->reportable(function (\Throwable $e) {
12+
error_log('[NATIVE_EXCEPTION]: '.$e->getMessage());
13+
});
14+
}
15+
}

src/NativeServiceProvider.php

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Native\Laravel\Commands\MinifyApplicationCommand;
1212
use Native\Laravel\Commands\SeedDatabaseCommand;
1313
use Native\Laravel\Events\EventWatcher;
14+
use Native\Laravel\Exceptions\Handler;
1415
use Native\Laravel\Logging\LogWatcher;
1516
use Spatie\LaravelPackageTools\Package;
1617
use Spatie\LaravelPackageTools\PackageServiceProvider;
@@ -44,6 +45,11 @@ public function packageRegistered()
4445
return new MigrateCommand($app['migrator'], $app['events']);
4546
});
4647

48+
$this->app->singleton(
49+
\Illuminate\Contracts\Debug\ExceptionHandler::class,
50+
Handler::class
51+
);
52+
4753
if (config('nativephp-internal.running')) {
4854
Artisan::starting(function ($artisan) {
4955
$artisan->resolveCommands([

0 commit comments

Comments
 (0)