简体   繁体   中英

How to customize the timeout 504 error page in laravel livewire?

I'm using laravel 9 and livewire v2. When a time-out error occurs, it currently shows a dark gray modal with black text which can be barely read as seen in the image.

I have customized other errors such as 404, 500, etc successfully with the laravel documentation. However this does not seem to work for a 504.

How can I customize this view?

在此处输入图像描述

The page itself is not coming from Laravel, it's an Nginx error page. You can customise this in your Nginx configuration, but the simplest approach is to intercept the response from the Livewire request's callback on error.

When you use the Livewire.onError JavaScript hook, you have to return false in order to prevent the default behaviour by Livewire.

Put the following JavaScript on your page somewhere after you have registered Livewire, and modify the action inside to do whatever is appropriate for you.

Livewire.onError((message, statusCode) => {
    if (statusCode == 504) {
        // Handle the timeout here, then return false
        return false;
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM