|
116 | 116 | if (this.version !== this.oldVersion) { |
117 | 117 | const ConfigurationMdUrl = |
118 | 118 | `https://raw.githubusercontent.com/rust-lang/rustfmt/${this.version}/Configurations.md`; |
| 119 | + let res; |
119 | 120 | 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; |
132 | 125 | } |
| 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; |
133 | 135 | } |
134 | 136 |
|
135 | 137 | const ast = this.configurationDescriptions |
|
172 | 174 | } |
173 | 175 | }, |
174 | 176 | 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 | + } |
176 | 184 | const reMajorVersion = /v(\d+)/; |
177 | 185 | const tagOptions = tags |
178 | 186 | .map(tag => tag.name) |
|
188 | 196 | this.scrolledOnce = true; |
189 | 197 | } |
190 | 198 | }); |
| 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 | + } |
191 | 223 | } |
192 | 224 | }); |
193 | 225 | const extractDepthOnes = (ast) => { |
|
0 commit comments