mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 15:34:44 +02:00
Merge pull request #334 from pelican-dev/issue/297
Better exception handling
This commit is contained in:
commit
b9d1ce4438
@ -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.');
|
||||||
|
@ -371,19 +371,20 @@ class CreateServer extends CreateRecord
|
|||||||
$text = Forms\Components\TextInput::make('variable_value')
|
$text = Forms\Components\TextInput::make('variable_value')
|
||||||
->hidden($this->shouldHideComponent(...))
|
->hidden($this->shouldHideComponent(...))
|
||||||
->maxLength(191)
|
->maxLength(191)
|
||||||
->rules([
|
->required(fn (Forms\Get $get) => in_array('required', explode('|', $get('rules'))))
|
||||||
|
->rules(
|
||||||
fn (Forms\Get $get): Closure => function (string $attribute, $value, Closure $fail) use ($get) {
|
fn (Forms\Get $get): Closure => function (string $attribute, $value, Closure $fail) use ($get) {
|
||||||
$validator = Validator::make(['validatorkey' => $value], [
|
$validator = Validator::make(['validatorkey' => $value], [
|
||||||
'validatorkey' => $get('rules'),
|
'validatorkey' => $get('rules'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
$message = str($validator->errors()->first())->replace('validatorkey', $get('name'));
|
$message = str($validator->errors()->first())->replace('validatorkey', $get('name'))->toString();
|
||||||
|
|
||||||
$fail($message);
|
$fail($message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
]);
|
);
|
||||||
|
|
||||||
$select = Forms\Components\Select::make('variable_value')
|
$select = Forms\Components\Select::make('variable_value')
|
||||||
->hidden($this->shouldHideComponent(...))
|
->hidden($this->shouldHideComponent(...))
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,10 +9,7 @@ return Application::configure(basePath: dirname(__DIR__))
|
|||||||
\Prologue\Alerts\AlertsServiceProvider::class,
|
\Prologue\Alerts\AlertsServiceProvider::class,
|
||||||
])
|
])
|
||||||
->withRouting(
|
->withRouting(
|
||||||
web: __DIR__.'/../routes/web.php',
|
|
||||||
// api: __DIR__.'/../routes/api.php',
|
|
||||||
commands: __DIR__.'/../routes/console.php',
|
commands: __DIR__.'/../routes/console.php',
|
||||||
// channels: __DIR__.'/../routes/channels.php',
|
|
||||||
health: '/up',
|
health: '/up',
|
||||||
)
|
)
|
||||||
->withMiddleware(function (Middleware $middleware) {
|
->withMiddleware(function (Middleware $middleware) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user