2025-03-28 10:53:15 +01:00
|
|
|
<script setup>
|
|
|
|
|
|
|
|
|
|
import { ref, useTemplateRef, onMounted } from 'vue';
|
2025-07-10 11:55:11 +02:00
|
|
|
import { fetcher } from '@cloudron/pankow';
|
2025-03-28 10:53:15 +01:00
|
|
|
import OfflineOverlay from '../components/OfflineOverlay.vue';
|
|
|
|
|
import ProfileModel from '../models/ProfileModel.js';
|
|
|
|
|
|
|
|
|
|
const profileModel = ProfileModel.create();
|
|
|
|
|
|
|
|
|
|
const offlineOverlay = useTemplateRef('offlineOverlay');
|
|
|
|
|
const ready = ref(false);
|
|
|
|
|
|
|
|
|
|
function onOnline() {
|
|
|
|
|
ready.value = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fetcher.globalOptions.errorHook = (error) => {
|
|
|
|
|
// network error, request killed by browser
|
|
|
|
|
if (error instanceof TypeError) {
|
|
|
|
|
ready.value = false;
|
|
|
|
|
return offlineOverlay.value.open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// re-login will make the code get a new token
|
|
|
|
|
if (error.status === 401) return profileModel.logout();
|
|
|
|
|
|
|
|
|
|
if (error.status === 500 || error.status === 501) {
|
|
|
|
|
// actual internal server error, most likely a bug or timeout log to console only to not alert the user
|
|
|
|
|
if (!ready.value) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
console.log('------\nCloudron Internal Error\n\nIf you see this, please send a mail with above log to support@cloudron.io\n------\n');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error.status >= 502) {
|
|
|
|
|
// This means the box service is not reachable. We just show offline banner for now
|
|
|
|
|
ready.value = false;
|
|
|
|
|
return offlineOverlay.value.open();
|
2023-02-22 15:59:23 +01:00
|
|
|
}
|
|
|
|
|
};
|
2023-02-19 17:13:33 +01:00
|
|
|
|
2025-03-28 10:53:15 +01:00
|
|
|
onMounted(() => {
|
|
|
|
|
ready.value = true;
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-19 17:13:33 +01:00
|
|
|
</script>
|
|
|
|
|
|
2025-01-19 12:00:22 +01:00
|
|
|
<template>
|
2025-03-28 10:53:15 +01:00
|
|
|
<div style="height: 100%;">
|
|
|
|
|
<OfflineOverlay ref="offlineOverlay" @online="onOnline()"/>
|
|
|
|
|
<router-view v-if="ready"></router-view>
|
|
|
|
|
</div>
|
2025-01-19 12:00:22 +01:00
|
|
|
</template>
|