Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API limit exceed: Show modal #184

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/components/board.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ class Board extends Component {
return (
<span>
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.
{err.message}
{JSON.stringify(err)}
</span>
);
}
Expand Down
58 changes: 36 additions & 22 deletions src/components/loadable.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Component} from 'react';
import {SyncIcon} from 'react-octicons';
import * as BS from 'react-bootstrap';

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

class Loadable extends Component {
static defaultProps = {
renderError: (err) => {
renderError: (err, show, close) => {
console.error(err);
// If it is a permissions error then it might be a rate limi
if (err.status === 403) {
return (
<div>
<h2>Insufficient Permissions (or rate limit exceeded)</h2>
<p>
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.
</p>
<code>{err.message}</code>
</div>
);
} else if (err.name === 'InvalidStateError') {
// If it is a permissions error then it might be a rate limit
if (err.name === 'InvalidStateError') {
return (
<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>
);
} else {
let message;
if(err.status === 403)
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.";
else
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.";
return (
<span>
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.
{err.message}
{JSON.stringify(err)}
</span>
<BS.Modal show={show}>
<BS.Modal.Header>
</BS.Modal.Header>
<BS.Modal.Body >
<div>
<p>
{message}
</p>
<code>
{JSON.parse(err.message).message}
<br />
<a href={JSON.parse(err.message).documentation_url}>Documentation URL</a>
</code>
<br />
<br />
<BS.Button onClick={close}>OK</BS.Button>
</div>
</BS.Modal.Body>
</BS.Modal>
);
}
}
};

state = {status: STATUS.INITIAL, value: null};
state = {status: STATUS.INITIAL, value: null, show: false};

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

onResolve = (value) => {
// TODO: Find out why this is being called multiple times
this.setState({status: STATUS.RESOLVED, value});
this.setState({status: STATUS.RESOLVED, value: value});
};

onError = (value) => {
// TODO: Find out why this is being called multiple times
if (this.state.status !== STATUS.ERROR) {
this.setState({status: STATUS.ERROR, value});
this.setState({status: STATUS.ERROR, value: value, show: true});
}
};

Expand All @@ -74,6 +84,10 @@ class Loadable extends Component {
);
};

close = () => {
this.setState({show: false});
}

render() {
const {status, value} = this.state;
let {renderLoading, renderLoaded, renderError} = this.props;
Expand All @@ -85,7 +99,7 @@ class Loadable extends Component {
} else if (status === STATUS.RESOLVED) {
return renderLoaded(value);
} else {
return renderError(value);
return renderError(value, this.state.show, this.close);
}
}
}
Expand Down