From 034b371ad4a5c21b85916c640cef0d26bfd84f35 Mon Sep 17 00:00:00 2001 From: jialin Date: Tue, 22 Apr 2025 16:49:41 +0800 Subject: [PATCH] fix: handle error as string when mismatch the field --- src/pages/playground/config/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pages/playground/config/index.ts b/src/pages/playground/config/index.ts index cb6c5b76..735dfe80 100644 --- a/src/pages/playground/config/index.ts +++ b/src/pages/playground/config/index.ts @@ -162,7 +162,7 @@ export const promptList = [ ]; export const extractErrorMessage = (result: any) => { - return ( + const errorMsg = result?.data?.data?.detail || result?.data?.data?.message || result?.data?.error?.message || @@ -173,9 +173,15 @@ export const extractErrorMessage = (result: any) => { result?.detail || result?.message || result?.error?.message || - result?.data || - 'Unknown error occurred' - ); + result?.data; + if (errorMsg) { + return errorMsg; + } + try { + return typeof result === 'string' ? result : JSON.stringify(result); + } catch { + return 'Unknown error'; + } }; export const scaleImageSize = (size: { width: number; height: number }) => {