Skip to content

Commit 4138e0c

Browse files
committed
Add exception handler to report exceptions in console
1 parent 1cb1c56 commit 4138e0c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Exceptions/Handler.php

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

src/NativeServiceProvider.php

Lines changed: 6 additions & 0 deletions
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)