generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle errors when checking for handled exceptions
- Loading branch information
1 parent
0245635
commit 20117ed
Showing
3 changed files
with
55 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Spatie\LaravelIgnition\FlareMiddleware; | ||
|
||
use Closure; | ||
use Spatie\Backtrace\Backtrace; | ||
use Spatie\FlareClient\FlareMiddleware\FlareMiddleware; | ||
use Spatie\FlareClient\Report; | ||
use Throwable; | ||
|
||
class AddExceptionHandledStatus implements FlareMiddleware | ||
{ | ||
public function handle(Report $report, Closure $next): Closure | ||
{ | ||
$frames = Backtrace::create()->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); | ||
} | ||
} |