|
115 | 115 | if (this.version !== this.oldVersion) {
|
116 | 116 | const ConfigurationMdUrl =
|
117 | 117 | `https://raw.githubusercontent.com/rust-lang/rustfmt/${this.version}/Configurations.md`;
|
| 118 | + let res; |
118 | 119 | try {
|
119 |
| - const res = await axios.get(ConfigurationMdUrl); |
120 |
| - const { |
121 |
| - about, |
122 |
| - configurationAbout, |
123 |
| - configurationDescriptions |
124 |
| - } = parseMarkdownAst(res.data); |
125 |
| - this.aboutHtml = marked.parser(about); |
126 |
| - this.configurationAboutHtml = marked.parser(configurationAbout); |
127 |
| - this.configurationDescriptions = configurationDescriptions; |
128 |
| - this.oldVersion = this.version; |
129 |
| - } catch(error) { |
130 |
| - this.aboutHtml = "<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>"; |
| 120 | + res = await axios.get(ConfigurationMdUrl).catch(e => { throw e }); |
| 121 | + } catch(e) { |
| 122 | + this.handleReqFailure(e); |
| 123 | + return; |
131 | 124 | }
|
| 125 | + const { |
| 126 | + about, |
| 127 | + configurationAbout, |
| 128 | + configurationDescriptions |
| 129 | + } = parseMarkdownAst(res.data); |
| 130 | + this.aboutHtml = marked.parser(about); |
| 131 | + this.configurationAboutHtml = marked.parser(configurationAbout); |
| 132 | + this.configurationDescriptions = configurationDescriptions; |
| 133 | + this.oldVersion = this.version; |
132 | 134 | }
|
133 | 135 |
|
134 | 136 | const ast = this.configurationDescriptions
|
|
171 | 173 | }
|
172 | 174 | },
|
173 | 175 | created: async function() {
|
174 |
| - const {data: tags} = await axios.get(RusfmtTagsUrl); |
| 176 | + let tags; |
| 177 | + try { |
| 178 | + tags = (await axios.get(RusfmtTagsUrl)).data; |
| 179 | + } catch(e) { |
| 180 | + this.handleReqFailure(e); |
| 181 | + return; |
| 182 | + } |
175 | 183 | const reMajorVersion = /v(\d+)/;
|
176 | 184 | const tagOptions = tags
|
177 | 185 | .map(tag => tag.name)
|
|
184 | 192 | if (target != null) {
|
185 | 193 | target.scrollIntoView(true);
|
186 | 194 | }
|
| 195 | + }, |
| 196 | + methods: { |
| 197 | + handleReqFailure(e) { |
| 198 | + if (e.response.status === 404) { |
| 199 | + this.aboutHtml = |
| 200 | + "<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>"; |
| 201 | + } else if ( |
| 202 | + e.response.status === 403 && |
| 203 | + e.response.headers["X-RateLimit-Remaining"] === 0 |
| 204 | + ) { |
| 205 | + const resetDate = new Date( |
| 206 | + e.response.headers['X-RateLimit-Reset'] * 1000 |
| 207 | + ).toLocaleString(); |
| 208 | + this.aboutHtml = |
| 209 | + `<p>You have hit the GitHub API rate limit; documentation cannot be updated.` + |
| 210 | + `<p>The rate limit will be reset at ${resetDate}.</p>`; |
| 211 | + } else { |
| 212 | + this.aboutHtml = |
| 213 | + `<p>Ecountered an error when fetching documentation data:</p>` + |
| 214 | + `<pre><code>${e.response.data}</code></pre>` + |
| 215 | + `<p>We would appreciate <a href="https://github.com/rust-lang/rustfmt/issues/new?template=bug_report.md">a bug report</a>.` + |
| 216 | + `<p>Try refreshing the page.</p>`; |
| 217 | + } |
| 218 | + } |
187 | 219 | }
|
188 | 220 | });
|
189 | 221 | const extractDepthOnes = (ast) => {
|
|
0 commit comments