From f43ed88ebacb1cb1205cc46c3c1fa2d8f291f95e Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 26 Mar 2025 09:39:57 +0800 Subject: [PATCH] feat: optimize 502 error message (#6547) * fix: app error * fix: app warning --- packages/core/client/src/api-client/APIClient.ts | 11 ++++++++++- .../core/client/src/application/Application.tsx | 16 +--------------- .../client/src/nocobase-buildin-plugin/index.tsx | 11 ++++++++++- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/core/client/src/api-client/APIClient.ts b/packages/core/client/src/api-client/APIClient.ts index 1cbbcdacdd..3fe2711a2a 100644 --- a/packages/core/client/src/api-client/APIClient.ts +++ b/packages/core/client/src/api-client/APIClient.ts @@ -139,7 +139,16 @@ export class APIClient extends APIClientSDK { if (typeof error?.response?.data === 'string') { const tempElement = document.createElement('div'); tempElement.innerHTML = error?.response?.data; - return [{ message: tempElement.textContent || tempElement.innerText }]; + let message = tempElement.textContent || tempElement.innerText; + if (message.includes('Error occurred while trying')) { + message = 'The application may be starting up. Please try again later.'; + return [{ code: 'APP_WARNING', message }]; + } + if (message.includes('502 Bad Gateway')) { + message = 'The application may be starting up. Please try again later.'; + return [{ code: 'APP_WARNING', message }]; + } + return [{ message }]; } return ( error?.response?.data?.errors || diff --git a/packages/core/client/src/application/Application.tsx b/packages/core/client/src/application/Application.tsx index c441f1ae92..efe709fa21 100644 --- a/packages/core/client/src/application/Application.tsx +++ b/packages/core/client/src/application/Application.tsx @@ -350,23 +350,9 @@ export class Application { setTimeout(() => resolve(null), 1000); }); } - const toError = (error) => { - if (typeof error?.response?.data === 'string') { - const tempElement = document.createElement('div'); - tempElement.innerHTML = error?.response?.data; - return { message: tempElement.textContent || tempElement.innerText }; - } - if (error?.response?.data?.error) { - return error?.response?.data?.error; - } - if (error?.response?.data?.errors?.[0]) { - return error?.response?.data?.errors?.[0]; - } - return { message: error?.message }; - }; this.error = { code: 'LOAD_ERROR', - ...toError(error), + ...this.apiClient.toErrMessages(error)?.[0], }; console.error(error, this.error); } diff --git a/packages/core/client/src/nocobase-buildin-plugin/index.tsx b/packages/core/client/src/nocobase-buildin-plugin/index.tsx index b9d61e9123..cc706c760a 100644 --- a/packages/core/client/src/nocobase-buildin-plugin/index.tsx +++ b/packages/core/client/src/nocobase-buildin-plugin/index.tsx @@ -76,7 +76,7 @@ const useErrorProps = (app: Application, error: any) => { const AppError: FC<{ error: Error; app: Application }> = observer( ({ app, error }) => { - const props = useErrorProps(app, error); + const props = getProps(app); return (
= observer( status="error" title={app.i18n.t('App error')} subTitle={app.i18n.t(error?.message)} + {...props} extra={[