From 8a80f12b262e20d1f5c15c5d31b66746cabbb63d Mon Sep 17 00:00:00 2001 From: Aresn Date: Wed, 29 May 2024 10:26:45 +0800 Subject: [PATCH] Update useRequest.js --- composables/useRequest.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/composables/useRequest.js b/composables/useRequest.js index 6012c63..785158f 100644 --- a/composables/useRequest.js +++ b/composables/useRequest.js @@ -1,5 +1,4 @@ const BASE_URL = 'https://gpu-pod656e861afe3d944d6b3ce77e-7862.node.inscode.run' - const request = async (url, options = {}) => { const token = useCookie('token') const fullUrl = BASE_URL + url @@ -20,6 +19,21 @@ const request = async (url, options = {}) => { }, onResponseError({ request, response, options }) { + const status = response.status + if (process.client && (status === 401 || status === 403)) { + let title + if (status === 401) title = '抱歉,您没有权限操作' + else if (status === 403) title = '抱歉,您没有权限访问当前内容' + nextTick(() => { + const toast = useToast() + toast.add({ + icon: 'i-heroicons-exclamation-triangle-20-solid', + timeout: 3000, + title: title, + color: 'red' + }) + }) + } // 处理响应错误 console.log('[ResponseError]', request) } -- GitLab