Skip to content

Commit

Permalink
Add exception handler (#398)
Browse files Browse the repository at this point in the history
* Add exception handler to report exceptions in console

* Fix styling

---------

Co-authored-by: simonhamp <[email protected]>
  • Loading branch information
simonhamp and simonhamp authored Nov 3, 2024
1 parent 1cb1c56 commit d8a09b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Native\Laravel\Exceptions;

class Handler extends \Illuminate\Foundation\Exceptions\Handler
{
protected $internalDontReport = [];

public function register(): void
{
$this->reportable(function (\Throwable $e) {
error_log('[NATIVE_EXCEPTION]: '.$e->getMessage());
});
}
}
6 changes: 6 additions & 0 deletions src/NativeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Native\Laravel\Commands\MinifyApplicationCommand;
use Native\Laravel\Commands\SeedDatabaseCommand;
use Native\Laravel\Events\EventWatcher;
use Native\Laravel\Exceptions\Handler;
use Native\Laravel\Logging\LogWatcher;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand Down Expand Up @@ -44,6 +45,11 @@ public function packageRegistered()
return new MigrateCommand($app['migrator'], $app['events']);
});

$this->app->singleton(
\Illuminate\Contracts\Debug\ExceptionHandler::class,
Handler::class
);

if (config('nativephp-internal.running')) {
Artisan::starting(function ($artisan) {
$artisan->resolveCommands([
Expand Down

0 comments on commit d8a09b8

Please sign in to comment.