Skip to content

Commit 1a366ef

Browse files
committed
Show error when backend is unavalaible
1 parent a3e9424 commit 1a366ef

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/layouts/DefaultLayout.vue

+15-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@
146146
<SplashScreen v-if="splashSrc" :img-url="splashSrc" :version="version" />
147147
<GlobalSearchComponent />
148148
</v-main>
149+
<v-snackbar
150+
v-model="showBackendError"
151+
timeout="-1"
152+
variant="text"
153+
location="top"
154+
>
155+
<v-alert type="error">Backend is unavailable</v-alert>
156+
</v-snackbar>
149157
</v-layout>
150158
</template>
151159

@@ -162,9 +170,10 @@ import SplashScreen from '@/components/general/SplashScreen.vue'
162170
import GlobalSearchComponent from '@/components/general/GlobalSearchComponent.vue'
163171
164172
import { configManager } from '@/services/application-config'
165-
import { getResourcesStaticUrl } from '@/lib/fews-config'
173+
import { getResourcesStaticUrl, isBackendAvailable } from '@/lib/fews-config'
166174
import { StyleValue, nextTick } from 'vue'
167175
import packageConfig from '../../package.json'
176+
import { asyncComputed } from '@vueuse/core'
168177
169178
const configStore = useConfigStore()
170179
const alertsStore = useAlertsStore()
@@ -181,6 +190,11 @@ const logoSrc = ref('')
181190
const splashSrc = ref<string>()
182191
const appBarStyle = ref<StyleValue>()
183192
const appBarColor = ref<string>('')
193+
const HEALTH_CHECK_TIMEOUT = 5000
194+
const showBackendError = asyncComputed(
195+
async () => !(await isBackendAvailable(HEALTH_CHECK_TIMEOUT)),
196+
false,
197+
)
184198
185199
function updateAppBarColor() {
186200
appBarColor.value = getComputedStyle(document.body).getPropertyValue(

src/lib/fews-config/index.ts

+23
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,26 @@ export function getResourcesIconsUrl(resource: string) {
4444
})
4545
return webServiceProvider.resourcesIconsUrl(resource).toString()
4646
}
47+
48+
export async function isBackendAvailable(timeout?: number) {
49+
const baseUrl = configManager.get('VITE_FEWS_WEBSERVICES_URL')
50+
51+
const controller = new AbortController()
52+
const DEFAULT_TIMEOUT = 5000
53+
const timeoutId = setTimeout(() => controller.abort(), timeout ?? DEFAULT_TIMEOUT)
54+
55+
const webServiceProvider = new PiWebserviceProvider(baseUrl, {
56+
transformRequestFn: createTransformRequestFn(controller),
57+
})
58+
59+
try {
60+
await webServiceProvider.getVersion()
61+
} catch (e) {
62+
if (e instanceof Error && e.name === 'AbortError') {
63+
return false
64+
}
65+
}
66+
67+
clearTimeout(timeoutId)
68+
return true
69+
}

0 commit comments

Comments
 (0)