From dd91aee89d578ab05189ad2a918abadcd613041c Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Fri, 2 Dec 2022 16:11:49 +0800 Subject: [PATCH] feat: export blob type error (#1170) --- .../core/client/src/api-client/APIClient.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/core/client/src/api-client/APIClient.ts b/packages/core/client/src/api-client/APIClient.ts index 503195645..5423f500b 100644 --- a/packages/core/client/src/api-client/APIClient.ts +++ b/packages/core/client/src/api-client/APIClient.ts @@ -3,6 +3,17 @@ import { Result } from 'ahooks/lib/useRequest/src/types'; import { notification } from 'antd'; import React from 'react'; +const handleErrorMessage = (error) => { + const reader = new FileReader(); + reader.readAsText(error?.response?.data, 'utf-8'); + reader.onload = function () { + notification.error({ + message: JSON.parse(reader.result as string).errors?.map?.((error: any) => { + return React.createElement('div', { children: error.message }); + }), + }); + }; +}; export class APIClient extends APIClientSDK { services: Record> = {}; @@ -23,11 +34,15 @@ export class APIClient extends APIClientSDK { if (redirectTo) { return (window.location.href = redirectTo); } - notification.error({ - message: error?.response?.data?.errors?.map?.((error: any) => { - return React.createElement('div', { children: error.message }); - }), - }); + if (error.response.data.type === 'application/json') { + handleErrorMessage(error); + } else { + notification.error({ + message: error?.response?.data?.errors?.map?.((error: any) => { + return React.createElement('div', { children: error.message }); + }), + }); + } throw error; }, );