From 924aad1304e393e87880df3fd0e8d5aa04eec380 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 25 Apr 2024 16:13:12 +0800 Subject: [PATCH] feat: toast the http request error (#5796) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /area ui /kind improvement /milestone 2.15.x #### What this PR does / why we need it: 优化 Console 的请求异常提示,如果异常不满足原有的判断逻辑,最终将提示 status + statusText,不再显示未知错误,方便使用者根据异常提示进行排查。 image #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/5739 #### Special notes for your reviewer: 我的测试方式: 使用 Caddy 模拟请求异常: ``` :9000 encode gzip @blocked { path /apis/content.halo.run/v1alpha1/posts/** } respond @blocked 413 reverse_proxy 127.0.0.1:8090 ``` #### Does this PR introduce a user-facing change? ```release-note 优化 Console 的请求异常提示,方便异常排查。 ``` --- ui/src/utils/api-client.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ui/src/utils/api-client.ts b/ui/src/utils/api-client.ts index 68efb6bfe..f875cffec 100644 --- a/ui/src/utils/api-client.ts +++ b/ui/src/utils/api-client.ts @@ -116,6 +116,13 @@ axiosInstance.interceptors.response.use( return Promise.reject(error); } + // Final fallback + if (errorResponse.status) { + const { status, statusText } = errorResponse; + Toast.error([status, statusText].filter(Boolean).join(": ")); + return Promise.reject(error); + } + Toast.error(i18n.global.t("core.common.toast.unknown_error")); return Promise.reject(error);