feat: message for connection error
parent
976eb5583d
commit
5e6f14b5dc
|
@ -8,13 +8,18 @@ export async function fetchURL(url, opts) {
|
||||||
|
|
||||||
let { headers, ...rest } = opts;
|
let { headers, ...rest } = opts;
|
||||||
|
|
||||||
const res = await fetch(`${baseURL}${url}`, {
|
let res;
|
||||||
|
try {
|
||||||
|
res = await fetch(`${baseURL}${url}`, {
|
||||||
headers: {
|
headers: {
|
||||||
"X-Auth": store.state.jwt,
|
"X-Auth": store.state.jwt,
|
||||||
...headers,
|
...headers,
|
||||||
},
|
},
|
||||||
...rest,
|
...rest,
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return { status: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
if (res.headers.get("X-Renew-Token") === "true") {
|
if (res.headers.get("X-Renew-Token") === "true") {
|
||||||
await renew(store.state.jwt);
|
await renew(store.state.jwt);
|
||||||
|
|
|
@ -43,7 +43,8 @@
|
||||||
"errors": {
|
"errors": {
|
||||||
"forbidden": "You don't have permissions to access this.",
|
"forbidden": "You don't have permissions to access this.",
|
||||||
"internal": "Something really went wrong.",
|
"internal": "Something really went wrong.",
|
||||||
"notFound": "This location can't be reached."
|
"notFound": "This location can't be reached.",
|
||||||
|
"connection": "The server can't be reached."
|
||||||
},
|
},
|
||||||
"files": {
|
"files": {
|
||||||
"body": "Body",
|
"body": "Body",
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
<header-bar v-if="showHeader" showMenu showLogo />
|
<header-bar v-if="showHeader" showMenu showLogo />
|
||||||
|
|
||||||
<h2 class="message">
|
<h2 class="message">
|
||||||
<i class="material-icons">{{ icon }}</i>
|
<i class="material-icons">{{ info.icon }}</i>
|
||||||
<span>{{ message }}</span>
|
<span>{{ $t(info.message) }}</span>
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -13,6 +13,10 @@
|
||||||
import HeaderBar from "@/components/header/HeaderBar";
|
import HeaderBar from "@/components/header/HeaderBar";
|
||||||
|
|
||||||
const errors = {
|
const errors = {
|
||||||
|
0: {
|
||||||
|
icon: "cloud_off",
|
||||||
|
message: "errors.connection",
|
||||||
|
},
|
||||||
403: {
|
403: {
|
||||||
icon: "error",
|
icon: "error",
|
||||||
message: "errors.forbidden",
|
message: "errors.forbidden",
|
||||||
|
@ -33,11 +37,17 @@ export default {
|
||||||
HeaderBar,
|
HeaderBar,
|
||||||
},
|
},
|
||||||
props: ["errorCode", "showHeader"],
|
props: ["errorCode", "showHeader"],
|
||||||
data: function () {
|
computed: {
|
||||||
return {
|
code() {
|
||||||
icon: errors[this.errorCode].icon,
|
return this.errorCode === "0" ||
|
||||||
message: this.$t(errors[this.errorCode].message),
|
this.errorCode === "404" ||
|
||||||
};
|
this.errorCode === "403"
|
||||||
|
? parseInt(this.errorCode)
|
||||||
|
: 500;
|
||||||
|
},
|
||||||
|
info() {
|
||||||
|
return errors[this.code];
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<breadcrumbs base="/files" />
|
<breadcrumbs base="/files" />
|
||||||
|
|
||||||
<errors v-if="error" :errorCode="errorCode" />
|
<errors v-if="error" :errorCode="error.message" />
|
||||||
<component v-else-if="currentView" :is="currentView"></component>
|
<component v-else-if="currentView" :is="currentView"></component>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<h2 class="message delayed">
|
<h2 class="message delayed">
|
||||||
|
@ -67,11 +67,6 @@ export default {
|
||||||
return "preview";
|
return "preview";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
errorCode() {
|
|
||||||
return this.error.message === "404" || this.error.message === "403"
|
|
||||||
? parseInt(this.error.message)
|
|
||||||
: 500;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.fetchData();
|
this.fetchData();
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<errors v-else :errorCode="errorCode" />
|
<errors v-else :errorCode="error.message" />
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<div class="share">
|
<div class="share">
|
||||||
|
@ -230,11 +230,6 @@ export default {
|
||||||
humanTime: function () {
|
humanTime: function () {
|
||||||
return moment(this.req.modified).fromNow();
|
return moment(this.req.modified).fromNow();
|
||||||
},
|
},
|
||||||
errorCode() {
|
|
||||||
return this.error.message === "404" || this.error.message === "403"
|
|
||||||
? parseInt(this.error.message)
|
|
||||||
: 500;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations(["resetSelected", "updateRequest", "setLoading"]),
|
...mapMutations(["resetSelected", "updateRequest", "setLoading"]),
|
||||||
|
|
Loading…
Reference in New Issue