Skip to content

Commit dd2b661

Browse files
committed
loadable.jsx: Show modal on API limit exceed
This shows a modal with error message on exceeding API limit. Closes coala#127
1 parent b872c70 commit dd2b661

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

src/components/loadable.jsx

+36-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Component} from 'react';
22
import {SyncIcon} from 'react-octicons';
3+
import * as BS from 'react-bootstrap';
34

45
const STATUS = {
56
INITIAL: 'initial',
@@ -9,36 +10,45 @@ const STATUS = {
910

1011
class Loadable extends Component {
1112
static defaultProps = {
12-
renderError: (err) => {
13+
renderError: (err, show, close) => {
1314
console.error(err);
14-
// If it is a permissions error then it might be a rate limi
15-
if (err.status === 403) {
16-
return (
17-
<div>
18-
<h2>Insufficient Permissions (or rate limit exceeded)</h2>
19-
<p>
20-
It looks like either you do not have permission to see this repository or the rate limit for requests to GitHub has been exceeded. This usually happens when you are not logged in to gh-board. Try signing in to continue.
21-
</p>
22-
<code>{err.message}</code>
23-
</div>
24-
);
25-
} else if (err.name === 'InvalidStateError') {
15+
// If it is a permissions error then it might be a rate limit
16+
if (err.name === 'InvalidStateError') {
2617
return (
2718
<span>It looks like your browser is in private browsing mode. gh-board uses IndexedDB to cache requests to GitHub. Please disable Private Browsing to see it work.</span>
2819
);
2920
} else {
21+
let message;
22+
if(err.status === 403)
23+
message = "It looks like either you do not have permission to see this repository or the rate limit for requests to GitHub has been exceeded. This usually happens when you are not logged in to gh-board. Try signing in to continue.";
24+
else
25+
message = "Problem loading. Is it a valid repo? And have you exceeded your number of requests? Usually happens when not logged in because GitHub limits anonymous use of their API.";
3026
return (
31-
<span>
32-
Problem loading. Is it a valid repo? And have you exceeded your number of requests? Usually happens when not logged in because GitHub limits anonymous use of their API.
33-
{err.message}
34-
{JSON.stringify(err)}
35-
</span>
27+
<BS.Modal show={show}>
28+
<BS.Modal.Header>
29+
</BS.Modal.Header>
30+
<BS.Modal.Body >
31+
<div>
32+
<p>
33+
{message}
34+
</p>
35+
<code>
36+
{JSON.parse(err.message).message}
37+
<br />
38+
<a href={JSON.parse(err.message).documentation_url}>Documentation URL</a>
39+
</code>
40+
<br />
41+
<br />
42+
<BS.Button onClick={close}>OK</BS.Button>
43+
</div>
44+
</BS.Modal.Body>
45+
</BS.Modal>
3646
);
3747
}
3848
}
3949
};
4050

41-
state = {status: STATUS.INITIAL, value: null};
51+
state = {status: STATUS.INITIAL, value: null, show: false};
4252

4353
componentDidMount() {
4454
const {promise} = this.props;
@@ -54,13 +64,13 @@ class Loadable extends Component {
5464

5565
onResolve = (value) => {
5666
// TODO: Find out why this is being called multiple times
57-
this.setState({status: STATUS.RESOLVED, value});
67+
this.setState({status: STATUS.RESOLVED, value: value});
5868
};
5969

6070
onError = (value) => {
6171
// TODO: Find out why this is being called multiple times
6272
if (this.state.status !== STATUS.ERROR) {
63-
this.setState({status: STATUS.ERROR, value});
73+
this.setState({status: STATUS.ERROR, value: value, show: true});
6474
}
6575
};
6676

@@ -74,6 +84,10 @@ class Loadable extends Component {
7484
);
7585
};
7686

87+
close = () => {
88+
this.setState({show: false});
89+
}
90+
7791
render() {
7892
const {status, value} = this.state;
7993
let {renderLoading, renderLoaded, renderError} = this.props;
@@ -85,7 +99,7 @@ class Loadable extends Component {
8599
} else if (status === STATUS.RESOLVED) {
86100
return renderLoaded(value);
87101
} else {
88-
return renderError(value);
102+
return renderError(value, this.state.show, this.close);
89103
}
90104
}
91105
}

0 commit comments

Comments
 (0)