about summary refs log tree commit diff
path: root/docs
diff options
context:
space:
mode:
authorAyaz Hafiz <ayaz.hafiz.1@gmail.com>2020-07-15 18:27:19 -0700
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2021-08-17 21:55:26 -0500
commit5c7ac69393a20e18bcc07f0d69383bc6254d1b40 (patch)
tree56d0af66dec56f997c42b184e15a9fbeb27307b0 /docs
parentf5c782f321572e7eece7d42c51a049c1ae825b5a (diff)
downloadrust-5c7ac69393a20e18bcc07f0d69383bc6254d1b40.tar.gz
rust-5c7ac69393a20e18bcc07f0d69383bc6254d1b40.zip
Warn when rate limit is on docs page
Demo: https://5f0fad2f06c62143ac519413--festive-golick-afb5e0.netlify.app
Diffstat (limited to 'docs')
-rw-r--r--docs/index.html58
1 files changed, 45 insertions, 13 deletions
diff --git a/docs/index.html b/docs/index.html
index 3cc0c45a759..eb5ded4ac30 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -116,20 +116,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
@@ -172,7 +174,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)
@@ -188,6 +196,30 @@
                     this.scrolledOnce = 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) => {