]> git.immae.eu Git - github/bastienwirtz/homer.git/commitdiff
Allow non json reponse in fetch.
authorBastien Wirtz <bastien.wirtz@gmail.com>
Sun, 10 Oct 2021 08:37:20 +0000 (10:37 +0200)
committerBastien Wirtz <bastien.wirtz@gmail.com>
Sun, 10 Oct 2021 08:37:20 +0000 (10:37 +0200)
src/components/services/Ping.vue
src/mixins/service.js

index 6fd3ec57f987e34719e7b169f5adaa16ab604303..d1fda576eff412d964739c58d8e16a3ae0b11253 100644 (file)
@@ -9,10 +9,12 @@
 </template>
 
 <script>
+import service from "@/mixins/service.js";
 import Generic from "./Generic.vue";
 
 export default {
   name: "Ping",
+  mixins: [service],
   props: {
     item: Object,
   },
@@ -27,16 +29,8 @@ export default {
   },
   methods: {
     fetchStatus: async function () {
-      const url = `${this.item.url}`;
-      fetch(url, {
-        method: "HEAD",
-        cache: "no-cache",
-        credentials: "include",
-      })
-        .then((response) => {
-          if (!response.ok) {
-            throw Error(response.statusText);
-          }
+      this.fetch("/", { method: "HEAD", cache: "no-cache" }, false)
+        .then(() => {
           this.status = "online";
         })
         .catch(() => {
index ae23a2742bc5130fc4f08b9a16ab92192afa3f85..17fa6fcc95600f955a55014d878285f1a7c45a4f 100644 (file)
@@ -12,7 +12,7 @@ export default {
     }
   },
   methods: {
-    fetch: function (path, init) {
+    fetch: function (path, init, json = true) {
       let options = {};
 
       if (this.proxy?.useCredentials) {
@@ -35,7 +35,8 @@ export default {
         if (!response.ok) {
           throw new Error("Not 2xx response");
         }
-        return response.json();
+
+        return json ? response.json() : response;
       });
     },
   },