From e3f8c4c232f44f010c985dc9150e1f383ca9041e Mon Sep 17 00:00:00 2001 From: HolgerHatGarKeineNode <123783602+HolgerHatGarKeineNode@users.noreply.github.com> Date: Wed, 20 May 2026 10:54:12 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20**Handle=20MissingFileUploadsTra?= =?UTF-8?q?it=20exceptions=20gracefully**=20-=20=E2=9C=85=20Added=20detect?= =?UTF-8?q?ion=20logic=20for=20`MissingFileUploadsTraitException`=20to=20p?= =?UTF-8?q?revent=20500=20errors.=20-=20=F0=9F=9B=A0=EF=B8=8F=20Updated=20?= =?UTF-8?q?exception=20handling=20to=20return=20a=20400=20response=20for?= =?UTF-8?q?=20these=20scenarios.=20-=20=F0=9F=94=87=20Suppressed=20logging?= =?UTF-8?q?=20of=20`MissingFileUploadsTraitException`=20to=20reduce=20nois?= =?UTF-8?q?e.=20-=20=E2=9C=85=20Added=20tests=20to=20verify=20400=20respon?= =?UTF-8?q?ses=20and=20absence=20of=20log=20entries.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap/app.php | 17 ++++++- tests/Feature/MissingFileUploadsTraitTest.php | 49 +++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/MissingFileUploadsTraitTest.php diff --git a/bootstrap/app.php b/bootstrap/app.php index 0e9e09d..b78c56b 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -7,6 +7,7 @@ use Illuminate\Foundation\Application; use Illuminate\Foundation\Configuration\Exceptions; use Illuminate\Foundation\Configuration\Middleware; use Illuminate\Http\Request; +use Livewire\Features\SupportFileUploads\MissingFileUploadsTraitException; use Stefro\LaravelLangCountry\Middleware\LangCountrySession; return Application::configure(basePath: dirname(__DIR__)) @@ -61,7 +62,11 @@ return Application::configure(basePath: dirname(__DIR__)) return str_contains($e->getMessage(), '/storage/framework/views/'); }; - $exceptions->report(function (Throwable $e) use ($isStaleLivewireAsset, $isStaleCompiledView) { + $isMissingFileUploadsTrait = function (Throwable $e): bool { + return $e instanceof MissingFileUploadsTraitException; + }; + + $exceptions->report(function (Throwable $e) use ($isStaleLivewireAsset, $isStaleCompiledView, $isMissingFileUploadsTrait) { if ($isStaleLivewireAsset($e, request())) { return false; } @@ -69,9 +74,13 @@ return Application::configure(basePath: dirname(__DIR__)) if ($isStaleCompiledView($e)) { return false; } + + if ($isMissingFileUploadsTrait($e)) { + return false; + } }); - $exceptions->render(function (Throwable $e, Request $request) use ($isStaleLivewireAsset, $isStaleCompiledView) { + $exceptions->render(function (Throwable $e, Request $request) use ($isStaleLivewireAsset, $isStaleCompiledView, $isMissingFileUploadsTrait) { if ($isStaleLivewireAsset($e, $request)) { return response('', 404); } @@ -80,6 +89,10 @@ return Application::configure(basePath: dirname(__DIR__)) return response('', 503)->header('Retry-After', '5'); } + if ($isMissingFileUploadsTrait($e)) { + return response('', 400); + } + return null; }); })->create(); diff --git a/tests/Feature/MissingFileUploadsTraitTest.php b/tests/Feature/MissingFileUploadsTraitTest.php new file mode 100644 index 0000000..22f7970 --- /dev/null +++ b/tests/Feature/MissingFileUploadsTraitTest.php @@ -0,0 +1,49 @@ +'; + } + }; + + throw new MissingFileUploadsTraitException($component); +} + +it('returns 400 for MissingFileUploadsTraitException instead of 500', function () { + Route::get('/_test/missing-file-uploads-trait', function () { + throwMissingFileUploadsTraitException(); + }); + + $response = $this->get('/_test/missing-file-uploads-trait'); + + expect($response->status())->toBe(400); +}); + +it('does not report MissingFileUploadsTraitException to the logs', function () { + Log::spy(); + + Route::get('/_test/missing-file-uploads-trait-log', function () { + throwMissingFileUploadsTraitException(); + }); + + $this->get('/_test/missing-file-uploads-trait-log') + ->assertStatus(400); + + Log::shouldNotHaveReceived('error'); + Log::shouldNotHaveReceived('critical'); + Log::shouldNotHaveReceived('emergency'); +});