Skip to content

Commit

Permalink
Handle errors when checking for handled exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed May 2, 2024
1 parent ed86e92 commit 8b9abc1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 50 deletions.
4 changes: 2 additions & 2 deletions config/flare.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +56,7 @@
'max_chained_job_reporting_depth' => 5,
],
AddContext::class,
AddExceptionHandled::class,
AddExceptionHandledStatus::class,
CensorRequestBodyFields::class => [
'censor_fields' => [
'password',
Expand Down
48 changes: 0 additions & 48 deletions src/FlareMiddleware/AddExceptionHandled.php

This file was deleted.

53 changes: 53 additions & 0 deletions src/FlareMiddleware/AddExceptionHandledStatus.php
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);
}
}

0 comments on commit 8b9abc1

Please sign in to comment.