Browse Source

detect & show mojang issues

jomo 9 years ago
parent
commit
882b0753bc
2 changed files with 22 additions and 11 deletions
  1. 14 6
      lib/public/javascript/mojang.js
  2. 8 5
      lib/views/index.html.ejs

+ 14 - 6
lib/public/javascript/mojang.js

@@ -14,15 +14,23 @@ xhr.onload = function() {
   var error = null;
   var error = null;
 
 
   if (textures || session && skins) {
   if (textures || session && skins) {
-    error = "both";
+    error = "all";
   } else if (skins) {
   } else if (skins) {
-    error = "name";
+    error = "username";
   } else if (session) {
   } else if (session) {
-    error = "uuid";
+    error = "UUID";
   }
   }
 
 
-  console.log(error);
+  if (error) {
+    var warn = document.createElement("div");
+    warn.setAttribute("class", "alert alert-warning");
+    warn.setAttribute("role", "alert");
+    warn.innerHTML = "<h5>Mojang issues</h5> Mojang's servers are having trouble <i>right now</i>, this affects <b>" + error + "</b> requests at Crafatar. <small><a href=\"https://help.mojang.com\" target=\"_blank\">check status</a>";
+    document.querySelector("#alerts").appendChild(warn);
+  }
 };
 };
 
 
-xhr.open("GET", "https://status.mojang.com/check", true);
-xhr.send();
+document.addEventListener("DOMContentLoaded", function(event) {
+  xhr.open("GET", "https://status.mojang.com/check", true);
+  xhr.send();
+});

+ 8 - 5
lib/views/index.html.ejs

@@ -17,6 +17,7 @@
   <meta property="og:description" content="A blazing fast Minecraft avatar API with support for avatars, skins, and 3D renders.">
   <meta property="og:description" content="A blazing fast Minecraft avatar API with support for avatars, skins, and 3D renders.">
   <meta name="twitter:card" content="summary">
   <meta name="twitter:card" content="summary">
   <meta name="twitter:creator" content="@Crafatar">
   <meta name="twitter:creator" content="@Crafatar">
+  <script src="/javascript/mojang.js"></script>
 </head>
 </head>
 
 
 <body>
 <body>
@@ -53,11 +54,13 @@
   </div>
   </div>
   <div class="container">
   <div class="container">
     <section id="documentation">
     <section id="documentation">
-      <div class="alert alert-danger" role="alert">
-        <h5>Usernames are deprecated!</h5>
-        You should only use usernames for <i>testing</i>.<br>
-        Updates are slower, some features are not available, and it may <strong>break anytime</strong>!<br>
-        <i>We strongly advise you to use UUIDs instead of usernames.</i> <small><a href="#usernames">more info</a></small>
+      <div id="alerts">
+        <div class="alert alert-danger" role="alert">
+          <h5>Usernames are deprecated!</h5>
+          You should only use usernames for <i>testing</i>.<br>
+          Updates are slower, some features are not available, and it may <strong>break anytime</strong>!<br>
+          <i>We strongly advise you to use UUIDs instead of usernames.</i> <small><a href="#usernames">more info</a></small>
+        </div>
       </div>
       </div>
 
 
       <h2>Documentation</h2>
       <h2>Documentation</h2>