From 253568ef29a6bdd6665f3bab56c955320247380a Mon Sep 17 00:00:00 2001 From: josc146 Date: Tue, 26 Mar 2024 21:29:21 +0800 Subject: [PATCH] improve error messages --- .../src/pages/AudiotrackManager/AudiotrackEditor.tsx | 2 +- frontend/src/pages/Chat.tsx | 9 +++++++-- frontend/src/pages/Completion.tsx | 2 +- frontend/src/pages/Composition.tsx | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/AudiotrackManager/AudiotrackEditor.tsx b/frontend/src/pages/AudiotrackManager/AudiotrackEditor.tsx index c30f47d..dbd1869 100644 --- a/frontend/src/pages/AudiotrackManager/AudiotrackEditor.tsx +++ b/frontend/src/pages/AudiotrackManager/AudiotrackEditor.tsx @@ -494,7 +494,7 @@ const AudiotrackEditor: FC<{ setPrompt: (prompt: string) => void }> = observer(( commonStore.setTracks(tracks); refreshTracksTotalTime(); } else { - toast(r.statusText + '\n' + (await r.text()), { + toast('Failed to fetch - ' + r.status + ' - ' + r.statusText + ' - ' + (await r.text()), { type: 'error' }); } diff --git a/frontend/src/pages/Chat.tsx b/frontend/src/pages/Chat.tsx index 0bedf8f..c651869 100644 --- a/frontend/src/pages/Chat.tsx +++ b/frontend/src/pages/Chat.tsx @@ -608,7 +608,12 @@ const ChatPanel: FC = observer(() => { }, async onopen(response) { if (response.status !== 200) { - commonStore.conversation[answerId!].content += '\n[ERROR]\n```\n' + response.statusText + '\n' + (await response.text()) + '\n```'; + let errText = await response.text(); + try { + errText = JSON.stringify(JSON.parse(errText), null, 2); + } catch (e) { + } + commonStore.conversation[answerId!].content += '\n[ERROR]\n```\n' + response.status + ' - ' + response.statusText + '\n' + errText + '\n```'; commonStore.setConversation(commonStore.conversation); commonStore.setConversationOrder([...commonStore.conversationOrder]); setTimeout(scrollToBottom); @@ -746,7 +751,7 @@ const ChatPanel: FC = observer(() => { autoClose: 1000 }); } else { - toast(r.statusText + '\n' + (await r.text()), { + toast('Failed to fetch - ' + r.status + ' - ' + r.statusText + ' - ' + (await r.text()), { type: 'error' }); } diff --git a/frontend/src/pages/Completion.tsx b/frontend/src/pages/Completion.tsx index 29af57d..db7755d 100644 --- a/frontend/src/pages/Completion.tsx +++ b/frontend/src/pages/Completion.tsx @@ -132,7 +132,7 @@ const CompletionPanel: FC = observer(() => { }, async onopen(response) { if (response.status !== 200) { - toast(response.statusText + '\n' + (await response.text()), { + toast(response.status + ' - ' + response.statusText + ' - ' + (await response.text()), { type: 'error' }); } diff --git a/frontend/src/pages/Composition.tsx b/frontend/src/pages/Composition.tsx index 4dfa3b9..d523ed8 100644 --- a/frontend/src/pages/Composition.tsx +++ b/frontend/src/pages/Composition.tsx @@ -235,7 +235,7 @@ const CompositionPanel: FC = observer(() => { }, async onopen(response) { if (response.status !== 200) { - toast(response.statusText + '\n' + (await response.text()), { + toast(response.status + ' - ' + response.statusText + ' - ' + (await response.text()), { type: 'error' }); }