F
Filament9mo ago
sidrit

Redirect on HTTP Client exception

I'm trying to wrap my head around something here. I have a filament page (a custom one) with an Infolist. The infolist is used to display some data that is fetched remotely from another application. I set it all up with ->state($this->record->someMethod()). Works great. I'm trying to handle the cases where the underlying http request (made with Laravel's HTTP Client) may fail. I throw an exception (with ->throwIf()) and the client will throw a RequestException. I'm trying to catch this one in the Handler and the idea is to log the user out (seems counter-intuitive but it's a specification) and redirect the user to the /login page, In the Handler though the exception seems to be wrapped in a Spatie\LaravelIgnition\Exceptions\ViewException In a plain Laravel application this would work
$this->reportable(function (Throwable $e) {
if(($e instanceof ViewException && $e->getPrevious() instanceof RequestException) || $e instanceof RequestException) {
auth()->logout();
return redirect()->route('login');
}
});
$this->reportable(function (Throwable $e) {
if(($e instanceof ViewException && $e->getPrevious() instanceof RequestException) || $e instanceof RequestException) {
auth()->logout();
return redirect()->route('login');
}
});
and the user will be redirected but the returned redirect here it seems stuck somethere in the Livewire layers. Additionally if i try to make it renderable
$this->renderable(function (Throwable $e) {
if(($e instanceof ViewException && $e->getPrevious() instanceof RequestException) || $e instanceof RequestException) {
auth()->logout();
return redirect()->route('login');
}
});

$this->renderable(function (Throwable $e) {
if(($e instanceof ViewException && $e->getPrevious() instanceof RequestException) || $e instanceof RequestException) {
auth()->logout();
return redirect()->route('login');
}
});

I am getting Undefined property: Livewire\Features\SupportRedirects\Redirector::$headers Am i missing something obvious here? What's the recommended Filament way to handle exceptions/redirect?
Solution:
GitHub
Unable to Redirect to Routes in Custom Error Handling · Issue #4872...
Package filament/filament Package Version v2.16.41 Laravel Version v9.38.0 Livewire Version No response PHP Version PHP 8.1.6 Problem description A blank, white page was displayed when trying to re...
Jump to solution
1 Reply
Solution
sidrit
sidrit9mo ago
GitHub
Unable to Redirect to Routes in Custom Error Handling · Issue #4872...
Package filament/filament Package Version v2.16.41 Laravel Version v9.38.0 Livewire Version No response PHP Version PHP 8.1.6 Problem description A blank, white page was displayed when trying to re...
Want results from more Discord servers?
Add your server