triggerException.js 1.09 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,
  };
jim's avatar
jim committed
13
  triggerError = code => {
14 15 16 17
    this.setState({
      isloading: true,
    });
    this.props.dispatch({
18 19 20 21
      type: 'error/query',
      payload: {
        code,
      },
22 23 24 25
    });
  };
  render() {
    return (
26 27
      <Card>
        <Spin spinning={this.state.isloading} wrapperClassName={styles.trigger}>
28
          <Button type="danger" onClick={() => this.triggerError(401)}>
29 30
            触发401
          </Button>
31
          <Button type="danger" onClick={() => this.triggerError(403)}>
32 33
            触发403
          </Button>
34
          <Button type="danger" onClick={() => this.triggerError(500)}>
35 36
            触发500
          </Button>
37
          <Button type="danger" onClick={() => this.triggerError(404)}>
38 39 40 41
            触发404
          </Button>
        </Spin>
      </Card>
42 43 44
    );
  }
}