Skip to content

Commit

Permalink
loadable.jsx: Show modal on API limit exceed
Browse files Browse the repository at this point in the history
This shows a modal with error message on exceeding API limit.

Fixes #127
  • Loading branch information
123vivekr committed Feb 9, 2019
1 parent b872c70 commit 18faa87
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 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 @@ -11,28 +12,53 @@ class Loadable extends Component {
static defaultProps = {
renderError: (err) => {
console.error(err);
// If it is a permissions error then it might be a rate limi
// If it is a permissions error then it might be a rate limit
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>
<BS.Modal show >
<BS.Modal.Header>
<BS.Modal.Title><h2>Insufficient Permissions </h2>(or rate limit exceeded)</BS.Modal.Title>
</BS.Modal.Header>
<BS.Modal.Body >
<div>
<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>
{JSON.parse(err.message).message}
<br />
<a href={JSON.parse(err.message).documentation_url}>Documentation URL</a>
</code>
<br />
<br />
</div>
</BS.Modal.Body>
</BS.Modal>
);
} else 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 {
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 >
<BS.Modal.Header>
</BS.Modal.Header>
<BS.Modal.Body >
<div>
<p>
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.
</p>
<code>
{JSON.parse(err.message).message}
<br />
<a href={JSON.parse(err.message).documentation_url}>Documentation URL</a>
</code>
<br />
<br />
</div>
</BS.Modal.Body>
</BS.Modal>
);
}
}
Expand Down

0 comments on commit 18faa87

Please sign in to comment.