Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

xr0m3oz's avatar

Filament custom exeptions Notifications

I want to catch my exceptions that interrupt the code, but at the same time do not show the client of the site, an incomprehensible window with an error. And in the notification it shows the error text.

But I can't get the one that when I click on the submit form button, the button freezes and an error appears in the console.

But if I reload the page, the notification appears.

How can I finish this correctly?

    ->withExceptions(function (Exceptions $exceptions) {
        $exceptions->render(function (\App\Exceptions\FilamentNotificationException $e, $request) {
            \Filament\Notifications\Notification::make()
                ->title('Ошибка')
                ->body($e->getMessage())
                ->danger()
                ->send();

            return response()->json(['success' => true, 'message' => $e->getMessage()], 200);
        });
    })

bootstrap/app.php

1 like
4 replies
Sinnbeck's avatar

What error are you getting in the console ?

xr0m3oz's avatar

I want to replace the try-catch with this (bootstrap/app.php), which needs to be installed everywhere to get a user-friendly error notification.

I want to do it in one place and then just throw the required exception in the code.

Action::make('viewItems')
                    ->label('Перегляд')
                    ->modalHeading('Товары в Batch')
                    ->modalContent(fn ($record) => view('filament.modals.document-items', [
                        'batchId' => $record->id,
                    ]))
                    ->icon('heroicon-o-eye')
                    ->color('primary')
                    ->action(function ($record){
                        try {
                            BatchService::addShipmentDocumentToBatch($record);
                        }catch (FilamentNotificationException $e){
                            \Filament\Notifications\Notification::make()
                                ->title('Помилка')
                                ->body($e->getMessage())
                                ->danger()
                                ->send();
                        }
                    })
                    ->modalSubmitAction(fn (StaticAction $action) => $action->label('Створити док. на залишок')),

Please or to participate in this conversation.