feat(client): error handler
This commit is contained in:
parent
9db654047a
commit
a96f76b87a
@ -25,13 +25,25 @@ import {
|
|||||||
SystemSettingsShortcut,
|
SystemSettingsShortcut,
|
||||||
useRequest
|
useRequest
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import { Spin } from 'antd';
|
import { notification, Spin } from 'antd';
|
||||||
import 'antd/dist/antd.css';
|
import 'antd/dist/antd.css';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { I18nextProvider } from 'react-i18next';
|
import { I18nextProvider } from 'react-i18next';
|
||||||
import { Link, NavLink } from 'react-router-dom';
|
import { Link, NavLink } from 'react-router-dom';
|
||||||
import apiClient from './apiClient';
|
import apiClient from './apiClient';
|
||||||
|
|
||||||
|
apiClient.axios.interceptors.response.use(
|
||||||
|
(response) => response,
|
||||||
|
(error) => {
|
||||||
|
notification.error({
|
||||||
|
message: error?.response?.data?.errors?.map?.((error: any) => {
|
||||||
|
return <div>{error.message}</div>;
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const providers = [
|
const providers = [
|
||||||
// [HashRouter],
|
// [HashRouter],
|
||||||
// [MemoryRouter, { initialEntries: ['/'] }],
|
// [MemoryRouter, { initialEntries: ['/'] }],
|
||||||
|
@ -64,11 +64,11 @@ const useSignin = () => {
|
|||||||
return {
|
return {
|
||||||
async run() {
|
async run() {
|
||||||
await form.submit();
|
await form.submit();
|
||||||
const { data } = await api.resource('users').signin({
|
const response = await api.resource('users').signin({
|
||||||
values: form.values,
|
values: form.values,
|
||||||
});
|
});
|
||||||
if (data?.data?.token) {
|
if (response?.data?.data?.token) {
|
||||||
api.setBearerToken(data?.data?.token);
|
api.setBearerToken(response?.data?.data?.token);
|
||||||
history.push('/admin');
|
history.push('/admin');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -91,13 +91,15 @@ const useSignup = () => {
|
|||||||
return {
|
return {
|
||||||
async run() {
|
async run() {
|
||||||
await form.submit();
|
await form.submit();
|
||||||
await api.resource('users').signup({
|
const response = await api.resource('users').signup({
|
||||||
values: form.values,
|
values: form.values,
|
||||||
});
|
});
|
||||||
message.success('注册成功,即将跳转登录页');
|
if (response?.data) {
|
||||||
setTimeout(() => {
|
message.success('注册成功,即将跳转登录页');
|
||||||
history.push('/signin');
|
setTimeout(() => {
|
||||||
}, 2000);
|
history.push('/signin');
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user