diff --git a/packages/core/client/src/api-client/APIClient.ts b/packages/core/client/src/api-client/APIClient.ts index 5cd61ad37..6d13dc4fe 100644 --- a/packages/core/client/src/api-client/APIClient.ts +++ b/packages/core/client/src/api-client/APIClient.ts @@ -14,6 +14,8 @@ const handleErrorMessage = (error) => { }); }; }; + +const errorCache = new Map(); export class APIClient extends APIClientSDK { services: Record> = {}; silence = false; @@ -49,9 +51,24 @@ export class APIClient extends APIClientSDK { if (error?.response?.data?.type === 'application/json') { handleErrorMessage(error); } else { + if (errorCache.size > 10) { + errorCache.clear(); + } + let errs = error?.response?.data?.errors || [{ message: 'Server error' }]; + errs = errs.filter((error) => { + const lastTime = errorCache.get(error.message); + if (lastTime && new Date().getTime() - lastTime < 500) { + return false; + } + errorCache.set(error.message, new Date().getTime()); + return true; + }); + if (errs.length === 0) { + throw error; + } notification.error({ - message: error?.response?.data?.errors?.map?.((error: any) => { - return React.createElement('div', { children: error.message }); + message: errs?.map?.((error: any) => { + return React.createElement('div', {}, error.message); }), }); }