From ea6fa154e09afb2d640cee52d5c6bbb828dd48af Mon Sep 17 00:00:00 2001 From: zhaoying Date: Wed, 22 Apr 2026 10:17:21 +0800 Subject: [PATCH] fix(web): stream add default error message --- web/src/utils/stream.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/src/utils/stream.ts b/web/src/utils/stream.ts index ba966159..6ad1f785 100644 --- a/web/src/utils/stream.ts +++ b/web/src/utils/stream.ts @@ -2,7 +2,7 @@ * @Author: ZhaoYing * @Date: 2026-02-02 16:35:43 * @Last Modified by: ZhaoYing - * @Last Modified time: 2026-03-18 14:32:40 + * @Last Modified time: 2026-04-22 10:16:43 */ /** * Server-Sent Events (SSE) Stream Utility Module @@ -176,12 +176,12 @@ export const handleSSE = async (url: string, data: any, onMessage?: (data: SSEMe case 500: case 502: const errorData = await response.json(); - const errorInfo = errorData.error || i18n.t('common.serviceUpgrading'); + const errorInfo = errorData.error || errorData.msg || i18n.t('common.serviceUpgrading'); message.warning(errorInfo); throw new Error(errorData); case 400: const error = await response.json(); - const error400 = error.error || 'Bad Request'; + const error400 = error.error || error.msg || 'Bad Request'; message.warning(error400); throw new Error(error); case 403: @@ -190,7 +190,7 @@ export const handleSSE = async (url: string, data: any, onMessage?: (data: SSEMe throw new Error(errors); case 504: const errorJson = await response.json(); - const errorMsg = errorJson.error || i18n.t('common.serverError'); + const errorMsg = errorJson.error || errorJson.msg || i18n.t('common.serverError'); message.warning(errorMsg); throw new Error(errorJson); case 401: @@ -204,6 +204,13 @@ export const handleSSE = async (url: string, data: any, onMessage?: (data: SSEMe return; } break; + default: + if (!response.ok) { + const defaultData = await response.json().catch(() => ({})); + const defaultMsg = defaultData.error || defaultData.msg; + if (defaultMsg) message.warning(defaultMsg); + throw new Error(defaultMsg || `HTTP ${response.status}`); + } } if (!response.body) throw new Error('No response body');