From 8b9abc199a77070252e88d594f3f3c81bdb58ef8 Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Thu, 2 May 2024 15:24:22 +0200 Subject: [PATCH] Handle errors when checking for handled exceptions --- config/flare.php | 4 +- src/FlareMiddleware/AddExceptionHandled.php | 48 ----------------- .../AddExceptionHandledStatus.php | 53 +++++++++++++++++++ 3 files changed, 55 insertions(+), 50 deletions(-) delete mode 100644 src/FlareMiddleware/AddExceptionHandled.php create mode 100644 src/FlareMiddleware/AddExceptionHandledStatus.php diff --git a/config/flare.php b/config/flare.php index 111dd9d..c811478 100644 --- a/config/flare.php +++ b/config/flare.php @@ -6,7 +6,7 @@ use Spatie\FlareClient\FlareMiddleware\CensorRequestHeaders; use Spatie\LaravelIgnition\FlareMiddleware\AddDumps; use Spatie\LaravelIgnition\FlareMiddleware\AddEnvironmentInformation; -use Spatie\LaravelIgnition\FlareMiddleware\AddExceptionHandled; +use Spatie\LaravelIgnition\FlareMiddleware\AddExceptionHandledStatus; use Spatie\LaravelIgnition\FlareMiddleware\AddExceptionInformation; use Spatie\LaravelIgnition\FlareMiddleware\AddJobs; use Spatie\LaravelIgnition\FlareMiddleware\AddLogs; @@ -56,7 +56,7 @@ 'max_chained_job_reporting_depth' => 5, ], AddContext::class, - AddExceptionHandled::class, + AddExceptionHandledStatus::class, CensorRequestBodyFields::class => [ 'censor_fields' => [ 'password', diff --git a/src/FlareMiddleware/AddExceptionHandled.php b/src/FlareMiddleware/AddExceptionHandled.php deleted file mode 100644 index 18ce2b7..0000000 --- a/src/FlareMiddleware/AddExceptionHandled.php +++ /dev/null @@ -1,48 +0,0 @@ -limit(40)->frames(); - $frameCount = count($frames); - - foreach ($frames as $i => $frame) { - // Check first frame, probably Illuminate\Foundation\Exceptions\Handler::report() - // Next frame should be: Illuminate/Foundation/helpers.php::report() - - if ($frame->method !== 'report') { - continue; - } - - if ($frame->class === null) { - continue; - } - - if ($i === $frameCount - 1) { - continue; - } - - if ($frames[$i + 1]->class !== null) { - continue; - } - - if ($frames[$i + 1]->method !== 'report') { - continue; - } - - $report->handled(); - - break; - } - - return $next($report); - } -} diff --git a/src/FlareMiddleware/AddExceptionHandledStatus.php b/src/FlareMiddleware/AddExceptionHandledStatus.php new file mode 100644 index 0000000..9e9f20b --- /dev/null +++ b/src/FlareMiddleware/AddExceptionHandledStatus.php @@ -0,0 +1,53 @@ +limit(40)->frames(); + $frameCount = count($frames); + + try { + foreach ($frames as $i => $frame) { + // Check first frame, probably Illuminate\Foundation\Exceptions\Handler::report() + // Next frame should be: Illuminate/Foundation/helpers.php::report() + + if ($frame->method !== 'report') { + continue; + } + + if ($frame->class === null) { + continue; + } + + if ($i === $frameCount - 1) { + continue; + } + + if ($frames[$i + 1]->class !== null) { + continue; + } + + if ($frames[$i + 1]->method !== 'report') { + continue; + } + + $report->handled(); + + break; + } + } catch (Throwable) { + // Do nothing + } + + return $next($report); + } +}