Browse Source
* Increase global error handling * Increase global error handling * fix bug * rebase master * Change 401 to 403 * add triggerException style.lesspull/516/head
committed by
ddcat1115
10 changed files with 167 additions and 1 deletions
@ -0,0 +1,17 @@ |
|||
import { routerRedux } from 'dva/router'; |
|||
|
|||
const error = (e, dispatch) => { |
|||
if (e.name === 401 || e.name === 403) { |
|||
dispatch(routerRedux.push('/exception/403')); |
|||
return; |
|||
} |
|||
if (e.name <= 504 && e.name >= 500) { |
|||
dispatch(routerRedux.push('/exception/500')); |
|||
return; |
|||
} |
|||
if (e.name >= 404 && e.name < 422) { |
|||
dispatch(routerRedux.push('/exception/404')); |
|||
} |
|||
}; |
|||
|
|||
export default error; |
|||
@ -0,0 +1,42 @@ |
|||
import { query403, query404, query500 } from '../services/error'; |
|||
|
|||
export default { |
|||
namespace: 'error', |
|||
|
|||
state: { |
|||
error: '', |
|||
isloading: false, |
|||
}, |
|||
|
|||
effects: { |
|||
*query403(_, { call, put }) { |
|||
yield call(query403); |
|||
yield put({ |
|||
type: 'trigger', |
|||
payload: '403', |
|||
}); |
|||
}, |
|||
*query500(_, { call, put }) { |
|||
yield call(query500); |
|||
yield put({ |
|||
type: 'trigger', |
|||
payload: '500', |
|||
}); |
|||
}, |
|||
*query404(_, { call, put }) { |
|||
yield call(query404); |
|||
yield put({ |
|||
type: 'trigger', |
|||
payload: '404', |
|||
}); |
|||
}, |
|||
}, |
|||
|
|||
reducers: { |
|||
trigger(state, action) { |
|||
return { |
|||
error: action.payload, |
|||
}; |
|||
}, |
|||
}, |
|||
}; |
|||
@ -0,0 +1,7 @@ |
|||
.trigger { |
|||
background: "red"; |
|||
:global(.ant-btn) { |
|||
margin-right: 8px; |
|||
margin-bottom: 12px; |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
import React, { PureComponent } from 'react'; |
|||
import { Button, Spin } from 'antd'; |
|||
import { connect } from 'dva'; |
|||
import styles from './style.less'; |
|||
|
|||
@connect(state => ({ |
|||
isloading: state.error.isloading, |
|||
})) |
|||
export default class TriggerException extends PureComponent { |
|||
state={ |
|||
isloading: false, |
|||
} |
|||
trigger403 = () => { |
|||
this.setState({ |
|||
isloading: true, |
|||
}); |
|||
this.props.dispatch({ |
|||
type: 'error/query403', |
|||
}); |
|||
}; |
|||
trigger500 = () => { |
|||
this.setState({ |
|||
isloading: true, |
|||
}); |
|||
this.props.dispatch({ |
|||
type: 'error/query500', |
|||
}); |
|||
}; |
|||
trigger404 = () => { |
|||
this.setState({ |
|||
isloading: true, |
|||
}); |
|||
this.props.dispatch({ |
|||
type: 'error/query404', |
|||
}); |
|||
}; |
|||
render() { |
|||
return ( |
|||
<Spin spinning={this.state.isloading} wrapperClassName={styles.trigger}> |
|||
<Button type="danger" onClick={this.trigger403}> |
|||
触发403 |
|||
</Button> |
|||
<Button type="danger" onClick={this.trigger500}> |
|||
触发500 |
|||
</Button> |
|||
<Button type="danger" onClick={this.trigger404}> |
|||
触发404 |
|||
</Button> |
|||
</Spin> |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
import request from '../utils/request'; |
|||
|
|||
export async function query404() { |
|||
return request('/api/404'); |
|||
} |
|||
|
|||
export async function query403() { |
|||
return request('/api/403'); |
|||
} |
|||
|
|||
export async function query500() { |
|||
return request('/api/500'); |
|||
} |
|||
Loading…
Reference in new issue