feat(client): error handler

This commit is contained in:
chenos 2022-03-02 13:22:59 +08:00
parent 9db654047a
commit a96f76b87a
3 changed files with 23 additions and 9 deletions

View File

@ -25,13 +25,25 @@ import {
SystemSettingsShortcut,
useRequest
} from '@nocobase/client';
import { Spin } from 'antd';
import { notification, Spin } from 'antd';
import 'antd/dist/antd.css';
import React from 'react';
import { I18nextProvider } from 'react-i18next';
import { Link, NavLink } from 'react-router-dom';
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 = [
// [HashRouter],
// [MemoryRouter, { initialEntries: ['/'] }],

View File

@ -64,11 +64,11 @@ const useSignin = () => {
return {
async run() {
await form.submit();
const { data } = await api.resource('users').signin({
const response = await api.resource('users').signin({
values: form.values,
});
if (data?.data?.token) {
api.setBearerToken(data?.data?.token);
if (response?.data?.data?.token) {
api.setBearerToken(response?.data?.data?.token);
history.push('/admin');
}
},

View File

@ -91,13 +91,15 @@ const useSignup = () => {
return {
async run() {
await form.submit();
await api.resource('users').signup({
const response = await api.resource('users').signup({
values: form.values,
});
message.success('注册成功,即将跳转登录页');
setTimeout(() => {
history.push('/signin');
}, 2000);
if (response?.data) {
message.success('注册成功,即将跳转登录页');
setTimeout(() => {
history.push('/signin');
}, 2000);
}
},
};
};