check http status of json include; elaborate failures
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 13 May 2019 20:27:42 +0000 (22:27 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 13 May 2019 20:27:42 +0000 (22:27 +0200)
widget.html

index 387d3db7e16a55bf5b5be5cac63c58b1babf58d5..12d83e6e653f8f0307edfa3d93f658fcc5e3f27c 100644 (file)
 <p id="clan">No clan data</p>
 <script>
        fetch('/schtarr/inno.json')
-       .then(res => res.json())
+       .then(res => {
+               if (res.status != 200) {
+                       console.log('got %o', res)
+                       throw `status ${res.status}`
+               }
+               return res.json()
+       })
        .then(clan => {
                let tiernum = (rank) => rank <= 8 ? 1 : rank <= 25 ? 2 : rank <= 50 ? 3 : 4;
                document.getElementById('clan').outerHTML = `
@@ -54,7 +60,7 @@
                        }
                })
        })
-       .catch(error => console.log(error))
+       .catch(msg => console.error('include failure:', msg))
 </script>
 </body>