Allow non json reponse in fetch.

This commit is contained in:
Bastien Wirtz 2021-10-10 10:37:20 +02:00
parent efc2bbb856
commit 2fba043575
2 changed files with 7 additions and 12 deletions

View 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(() => {

View 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;
});
},
},