From 58dfc5166d25280e15bb9d823c6baa7857375c9f Mon Sep 17 00:00:00 2001 From: DongChen Lin <393227948@qq.com> Date: Thu, 28 Nov 2024 11:30:52 +0800 Subject: [PATCH] decode gui post error msg --- gui/src/service/common/request.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/gui/src/service/common/request.js b/gui/src/service/common/request.js index 7f170a8..79130c5 100644 --- a/gui/src/service/common/request.js +++ b/gui/src/service/common/request.js @@ -81,8 +81,25 @@ const getPort = () => { const setPort = (port) => { localStorage.setItem("VITE_APP_API_PORT",port); } -const toastMessage = (e) => { - if(!!e?.response?.status && !!e?.response?.data){ +const toastMessage = async (e) => { + let result = ''; + if (e?.body instanceof ReadableStream) { + const reader = e.body.getReader(); + const decoder = new TextDecoder('utf-8'); + let done = false; + + while (!done) { + const { value, done: readerDone } = await reader.read(); + done = readerDone; + if (value) { + result += decoder.decode(value, { stream: !done }); + } + } + } + + if(!!result){ + toast.add({ severity: 'error', summary: 'Tips', detail: `${result}`, life: 3000 }); + }else if(!!e?.response?.status && !!e?.response?.data){ toast.add({ severity: 'error', summary: 'Tips', detail: `[${e.response.status}] ${e.response.data}`, life: 3000 }); } else if(!!e.status && !!e.message){ toast.add({ severity: 'error', summary: 'Tips', detail: `[${e.status}] ${e.message}`, life: 3000 });