mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 07:34:45 +02:00
Better exception handling
This commit is contained in:
parent
6f009ee126
commit
df26c4f9f5
@ -6,9 +6,9 @@ use App\Exceptions\DisplayException;
|
|||||||
|
|
||||||
class TwoFactorAuthenticationTokenInvalid extends DisplayException
|
class TwoFactorAuthenticationTokenInvalid extends DisplayException
|
||||||
{
|
{
|
||||||
/**
|
public string $title = 'Invalid 2FA Code';
|
||||||
* TwoFactorAuthenticationTokenInvalid constructor.
|
public string $icon = 'tabler-2fa';
|
||||||
*/
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct('The provided two-factor authentication token was not valid.');
|
parent::__construct('The provided two-factor authentication token was not valid.');
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Filament\Resources\UserResource\Pages;
|
namespace App\Filament\Resources\UserResource\Pages;
|
||||||
|
|
||||||
use App\Filament\Resources\UserResource;
|
use App\Filament\Resources\UserResource;
|
||||||
|
use App\Services\Exceptions\FilamentExceptionHandler;
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
use Filament\Resources\Pages\EditRecord;
|
use Filament\Resources\Pages\EditRecord;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@ -77,4 +78,9 @@ class EditUser extends EditRecord
|
|||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function exception($exception, $stopPropagation): void
|
||||||
|
{
|
||||||
|
(new FilamentExceptionHandler())->handle($exception, $stopPropagation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
24
app/Services/Exceptions/FilamentExceptionHandler.php
Normal file
24
app/Services/Exceptions/FilamentExceptionHandler.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
|
||||||
|
class FilamentExceptionHandler
|
||||||
|
{
|
||||||
|
public function handle(Exception $exception, Callable $stopPropagation): void
|
||||||
|
{
|
||||||
|
Notification::make()
|
||||||
|
->title($exception->title ?? null)
|
||||||
|
->body($exception->body ?? $exception->getMessage())
|
||||||
|
->color($exception->color ?? 'danger')
|
||||||
|
->icon($exception->icon ?? 'tabler-x')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
if ($this->stopPropagation ?? true) {
|
||||||
|
$stopPropagation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user