Skip to content

Warn when rate limit is on docs page #4330

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

Merged
merged 1 commit into from
Jul 16, 2020
Merged
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
58 changes: 45 additions & 13 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,22 @@
if (this.version !== this.oldVersion) {
const ConfigurationMdUrl =
`https://raw.githubusercontent.com/rust-lang/rustfmt/${this.version}/Configurations.md`;
let res;
try {
const res = await axios.get(ConfigurationMdUrl);
const {
about,
configurationAbout,
configurationDescriptions
} = parseMarkdownAst(res.data);
this.aboutHtml = marked.parser(about);
this.configurationAboutHtml = marked.parser(configurationAbout);
this.configurationDescriptions = configurationDescriptions;
this.oldVersion = this.version;
} catch(error) {
this.aboutHtml = "<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>";
res = await axios.get(ConfigurationMdUrl).catch(e => { throw e });
} catch(e) {
this.handleReqFailure(e);
return;
}
const {
about,
configurationAbout,
configurationDescriptions
} = parseMarkdownAst(res.data);
this.aboutHtml = marked.parser(about);
this.configurationAboutHtml = marked.parser(configurationAbout);
this.configurationDescriptions = configurationDescriptions;
this.oldVersion = this.version;
}

const ast = this.configurationDescriptions
Expand Down Expand Up @@ -171,7 +173,13 @@
}
},
created: async function() {
const {data: tags} = await axios.get(RusfmtTagsUrl);
let tags;
try {
tags = (await axios.get(RusfmtTagsUrl)).data;
} catch(e) {
this.handleReqFailure(e);
return;
}
const reMajorVersion = /v(\d+)/;
const tagOptions = tags
.map(tag => tag.name)
Expand All @@ -184,6 +192,30 @@
if (target != null) {
target.scrollIntoView(true);
}
},
methods: {
handleReqFailure(e) {
if (e.response.status === 404) {
this.aboutHtml =
"<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>";
} else if (
e.response.status === 403 &&
e.response.headers["X-RateLimit-Remaining"] === 0
) {
const resetDate = new Date(
e.response.headers['X-RateLimit-Reset'] * 1000
).toLocaleString();
this.aboutHtml =
`<p>You have hit the GitHub API rate limit; documentation cannot be updated.` +
`<p>The rate limit will be reset at ${resetDate}.</p>`;
} else {
this.aboutHtml =
`<p>Ecountered an error when fetching documentation data:</p>` +
`<pre><code>${e.response.data}</code></pre>` +
`<p>We would appreciate <a href="https://github.com/rust-lang/rustfmt/issues/new?template=bug_report.md">a bug report</a>.` +
`<p>Try refreshing the page.</p>`;
}
}
}
});
const extractDepthOnes = (ast) => {
Expand Down