mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-05-20 20:55:36 +00:00
🐛 **Handle MissingFileUploadsTrait exceptions gracefully**
- ✅ Added detection logic for `MissingFileUploadsTraitException` to prevent 500 errors. - 🛠️ Updated exception handling to return a 400 response for these scenarios. - 🔇 Suppressed logging of `MissingFileUploadsTraitException` to reduce noise. - ✅ Added tests to verify 400 responses and absence of log entries.
This commit is contained in:
+15
-2
@@ -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();
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Livewire\Component;
|
||||
use Livewire\Features\SupportFileUploads\MissingFileUploadsTraitException;
|
||||
|
||||
function throwMissingFileUploadsTraitException(): never
|
||||
{
|
||||
$component = new class extends Component
|
||||
{
|
||||
public function getName(): string
|
||||
{
|
||||
return 'language.selector';
|
||||
}
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
return '<div></div>';
|
||||
}
|
||||
};
|
||||
|
||||
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');
|
||||
});
|
||||
Reference in New Issue
Block a user