feat: export blob type error (#1170)

This commit is contained in:
katherinehhh 2022-12-02 16:11:49 +08:00 committed by GitHub
parent eee4cabd64
commit dd91aee89d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<string, Result<any, any>> = {};
@ -23,11 +34,15 @@ export class APIClient extends APIClientSDK {
if (redirectTo) {
return (window.location.href = redirectTo);
}
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;
},
);