Skip to content

Commit ccd6798

Browse files
ayazhafizcalebcartwright
authored andcommitted
1 parent 586c3db commit ccd6798

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

docs/index.html

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,22 @@
116116
if (this.version !== this.oldVersion) {
117117
const ConfigurationMdUrl =
118118
`https://raw.githubusercontent.com/rust-lang/rustfmt/${this.version}/Configurations.md`;
119+
let res;
119120
try {
120-
const res = await axios.get(ConfigurationMdUrl);
121-
const {
122-
about,
123-
configurationAbout,
124-
configurationDescriptions
125-
} = parseMarkdownAst(res.data);
126-
this.aboutHtml = marked.parser(about);
127-
this.configurationAboutHtml = marked.parser(configurationAbout);
128-
this.configurationDescriptions = configurationDescriptions;
129-
this.oldVersion = this.version;
130-
} catch(error) {
131-
this.aboutHtml = "<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>";
121+
res = await axios.get(ConfigurationMdUrl).catch(e => { throw e });
122+
} catch(e) {
123+
this.handleReqFailure(e);
124+
return;
132125
}
126+
const {
127+
about,
128+
configurationAbout,
129+
configurationDescriptions
130+
} = parseMarkdownAst(res.data);
131+
this.aboutHtml = marked.parser(about);
132+
this.configurationAboutHtml = marked.parser(configurationAbout);
133+
this.configurationDescriptions = configurationDescriptions;
134+
this.oldVersion = this.version;
133135
}
134136

135137
const ast = this.configurationDescriptions
@@ -172,7 +174,13 @@
172174
}
173175
},
174176
created: async function() {
175-
const {data: tags} = await axios.get(RusfmtTagsUrl);
177+
let tags;
178+
try {
179+
tags = (await axios.get(RusfmtTagsUrl)).data;
180+
} catch(e) {
181+
this.handleReqFailure(e);
182+
return;
183+
}
176184
const reMajorVersion = /v(\d+)/;
177185
const tagOptions = tags
178186
.map(tag => tag.name)
@@ -188,6 +196,30 @@
188196
this.scrolledOnce = true;
189197
}
190198
});
199+
},
200+
methods: {
201+
handleReqFailure(e) {
202+
if (e.response.status === 404) {
203+
this.aboutHtml =
204+
"<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>";
205+
} else if (
206+
e.response.status === 403 &&
207+
e.response.headers["X-RateLimit-Remaining"] === 0
208+
) {
209+
const resetDate = new Date(
210+
e.response.headers['X-RateLimit-Reset'] * 1000
211+
).toLocaleString();
212+
this.aboutHtml =
213+
`<p>You have hit the GitHub API rate limit; documentation cannot be updated.` +
214+
`<p>The rate limit will be reset at ${resetDate}.</p>`;
215+
} else {
216+
this.aboutHtml =
217+
`<p>Ecountered an error when fetching documentation data:</p>` +
218+
`<pre><code>${e.response.data}</code></pre>` +
219+
`<p>We would appreciate <a href="https://github.com/rust-lang/rustfmt/issues/new?template=bug_report.md">a bug report</a>.` +
220+
`<p>Try refreshing the page.</p>`;
221+
}
222+
}
191223
}
192224
});
193225
const extractDepthOnes = (ast) => {

0 commit comments

Comments
 (0)