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

Prido's avatar
Level 2

LiverWire

How to catch http request errors like when the browser cannot access the internet, basically i am showing errors when sever returns any, but wen network fails to connect i see no errors

0 likes
6 replies
Prido's avatar
Level 2

@OussamaMater i have a wire loading and wen the internet is weak, request fails as normal then wire loading stops, no error is shown but user have to know request failed

sAnsic's avatar

@OussamaMater wire:offline just notifies you when the connection is gone. But what to do if there is such a situation:

  1. The user presses the Submit button (a request is sent to the server)
  2. At this moment, the connection disappears (access to the Internet)
  3. We receive:
POST https://foo.com/livewire/message/my_component net::ERR_INTERNET_DISCONNECTED ... Uncaught (in promise) TypeError: Failed to fetch
  1. And after step 3, the application crashes - the component stops working (the Submit button no longer works, the data from the inputs is not transferred to the server).

I think the author asked kakraz about this situation. Not just to tell the user that the application is offline, but to say that perhaps nothing has been saved. Better yet, prevent the app from crashing.

1 like
Prido's avatar
Level 2

The thing is here is my code of the loader bellow

<div wire:loading.class="show" wire:target="store" class="loading-spinner-wrapper">
        <span class="spinner-loader"></span>
    </div>

so wen the browser losses connection the loading disappears, but i want to be able to show user that request failed.

OussamaMater's avatar

@Prido yes I already answer this, you add a different div to show the error in case of internet loss

<div wire:offline>
   <span>you lost your internet connection</span>
</div>

<div wire:loading.class="show" wire:target="store" class="loading-spinner-wrapper">
   <span class="spinner-loader"></span>
</div>

Please or to participate in this conversation.