From 303c5e43633f1a38337ea50839e02d534fcd9d8f Mon Sep 17 00:00:00 2001 From: niko <644506165@qq.com> Date: Mon, 19 Mar 2018 18:54:17 +0800 Subject: [PATCH] Remove Error Trigger dump code & support static env (#1128) * remove dump code * compatibility for static --- src/models/error.js | 32 ++++-------------- src/routes/Exception/triggerException.js | 41 ++++++------------------ src/services/error.js | 16 ++------- 3 files changed, 19 insertions(+), 70 deletions(-) diff --git a/src/models/error.js b/src/models/error.js index c2508f67..01431f4c 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 e552d4db..0a2d489e 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 9697b7ee..7e1eeee1 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}`); } -- GitLab