diff --git a/src/models/error.js b/src/models/error.js index c2508f674d435728a8c7a3eb54ac5aba2b2f1c41..01431f4cd0839683cb252ae2ec35995a4d88a5c6 100644 --- a/src/models/error.js +++ b/src/models/error.js @@ -1,4 +1,5 @@ -import { query403, query401, query404, query500 } from '../services/error'; +import { routerRedux } from 'dva/router'; +import { query } from '../services/error'; export default { namespace: 'error', @@ -9,32 +10,13 @@ export default { }, effects: { - *query403(_, { call, put }) { - yield call(query403); + *query({ payload }, { call, put }) { + yield call(query, payload.code); + // redirect on client when network broken + yield put(routerRedux.push(`/exception/${payload.code}`)); yield put({ type: 'trigger', - payload: '403', - }); - }, - *query401(_, { call, put }) { - yield call(query401); - yield put({ - type: 'trigger', - payload: '401', - }); - }, - *query500(_, { call, put }) { - yield call(query500); - yield put({ - type: 'trigger', - payload: '500', - }); - }, - *query404(_, { call, put }) { - yield call(query404); - yield put({ - type: 'trigger', - payload: '404', + payload: payload.code, }); }, }, diff --git a/src/routes/Exception/triggerException.js b/src/routes/Exception/triggerException.js index e552d4db02038664d89e1403e18fe9ecf0550ee8..0a2d489ecba47595cf6de36a6569de9fbb7c235e 100644 --- a/src/routes/Exception/triggerException.js +++ b/src/routes/Exception/triggerException.js @@ -7,55 +7,34 @@ import styles from './style.less'; isloading: state.error.isloading, })) export default class TriggerException extends PureComponent { - state={ + state = { isloading: false, - } - trigger401 = () => { - this.setState({ - isloading: true, - }); - this.props.dispatch({ - type: 'error/query401', - }); - }; - trigger403 = () => { - this.setState({ - isloading: true, - }); - this.props.dispatch({ - type: 'error/query403', - }); - }; - trigger500 = () => { - this.setState({ - isloading: true, - }); - this.props.dispatch({ - type: 'error/query500', - }); }; - trigger404 = () => { + triggerError = (code) => { this.setState({ isloading: true, }); this.props.dispatch({ - type: 'error/query404', + type: 'error/query', + payload: { + code, + }, }); }; render() { return ( - - - - diff --git a/src/services/error.js b/src/services/error.js index 9697b7eed2c49f977a0dcc327d995cbb14cf9ea1..7e1eeee1948fcbcd725af01420b7905432816b93 100644 --- a/src/services/error.js +++ b/src/services/error.js @@ -1,17 +1,5 @@ import request from '../utils/request'; -export async function query404() { - return request('/api/404'); -} - -export async function query401() { - return request('/api/401'); -} - -export async function query403() { - return request('/api/403'); -} - -export async function query500() { - return request('/api/500'); +export async function query(code) { + return request(`/api/${code}`); }