From f72480425c745d379be4d4b3a33922cd95977e29 Mon Sep 17 00:00:00 2001 From: actiontech-zihan Date: Wed, 22 Apr 2026 06:55:49 +0000 Subject: [PATCH] fix(dms-kit): add defensive type check in useTableRequestError to prevent crash on non-JSON response When backend API returns HTML instead of JSON (e.g., unregistered route falling through to static file middleware), response.data is a string. Using 'in' operator on a string throws TypeError. Add typeof check before accessing response.data properties, and set error message instead of crashing. #787 --- .../ActiontechTable/hooks/useTableRequestError.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/dms-kit/src/components/ActiontechTable/hooks/useTableRequestError.tsx b/packages/dms-kit/src/components/ActiontechTable/hooks/useTableRequestError.tsx index 88e179b896..f6e00ec08f 100644 --- a/packages/dms-kit/src/components/ActiontechTable/hooks/useTableRequestError.tsx +++ b/packages/dms-kit/src/components/ActiontechTable/hooks/useTableRequestError.tsx @@ -18,6 +18,15 @@ const useTableRequestError = () => { return request .then((response) => { setRequestErrorMessage(''); + if ( + typeof response.data !== 'object' || + response.data === null + ) { + setRequestErrorMessage( + 'Unexpected response format: expected JSON but received non-object data' + ); + return { list: [], total: 0, otherData: {} }; + } if ('data' in response.data && 'total_nums' in response.data) { const { data, total_nums, ...otherData } = response.data; return {