triggerException.js 1.1 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 18
    this.setState({
      isloading: true,
    });
    this.props.dispatch({
19 20 21 22
      type: 'error/query',
      payload: {
        code,
      },
23 24
    });
  };
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
25

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