feat: message for connection error

pull/1373/head
Ramires Viana 2021-04-16 14:01:10 +00:00
parent 976eb5583d
commit 5e6f14b5dc
5 changed files with 33 additions and 27 deletions

View File

@ -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);

View File

@ -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",

View File

@ -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>

View File

@ -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();

View File

@ -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"]),