TriggerException.js 1.15 KB
Newer Older
1
import React, { PureComponent } from 'react';
2
import { Button, Spin, Card } from 'antd';
3 4 5
import { connect } from 'dva';
import styles from './style.less';

afc163's avatar
afc163 committed
6
export default
7 8 9
@connect(state => ({
  isloading: state.error.isloading,
}))
afc163's avatar
afc163 committed
10
class TriggerException extends PureComponent {
11
  state = {
12 13
    isloading: false,
  };
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
14

jim's avatar
jim committed
15
  triggerError = code => {
16 17 18
    this.setState({
      isloading: true,
    });
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
19 20
    const { dispatch } = this.props;
    dispatch({
21 22 23 24
      type: 'error/query',
      payload: {
        code,
      },
25 26
    });
  };
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
27

28
  render() {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
29
    const { isloading } = this.state;
30
    return (
31
      <Card>
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
32
        <Spin spinning={isloading} wrapperClassName={styles.trigger}>
33
          <Button type="danger" onClick={() => this.triggerError(401)}>
34 35
            触发401
          </Button>
36
          <Button type="danger" onClick={() => this.triggerError(403)}>
37 38
            触发403
          </Button>
39
          <Button type="danger" onClick={() => this.triggerError(500)}>
40 41
            触发500
          </Button>
42
          <Button type="danger" onClick={() => this.triggerError(404)}>
43 44 45 46
            触发404
          </Button>
        </Spin>
      </Card>
47 48 49
    );
  }
}