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

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

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

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