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'); +});