简体   繁体   English

如何在 laravel livewire 中自定义超时 504 错误页面?

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

I'm using laravel 9 and livewire v2.我正在使用 laravel 9 和 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.我已经使用 laravel 文档成功自定义了其他错误,例如 404、500 等。 However this does not seem to work for a 504.但是,这似乎不适用于 504。

How can I customize this view?如何自定义此视图?

在此处输入图像描述

The page itself is not coming from Laravel, it's an Nginx error page.该页面本身不是来自 Laravel,而是 Nginx 错误页面。 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.您可以在 Nginx 配置中对此进行自定义,但最简单的方法是拦截来自 Livewire 请求的错误回调的响应。

When you use the Livewire.onError JavaScript hook, you have to return false in order to prevent the default behaviour by Livewire.当您使用Livewire.onError JavaScript 挂钩时,您必须return false以防止 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 后,将以下 JavaScript 放在页面上的某个位置,然后修改里面的操作以执行适合您的任何操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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