diff --git a/frontend/src/lib/services/app-config-service.ts b/frontend/src/lib/services/app-config-service.ts index 1469822..eeea23d 100644 --- a/frontend/src/lib/services/app-config-service.ts +++ b/frontend/src/lib/services/app-config-service.ts @@ -1,6 +1,6 @@ import { version as currentVersion } from '$app/environment'; import type { AllAppConfig, AppConfigRawResponse } from '$lib/types/application-configuration'; -import axios from 'axios'; +import axios, { AxiosError } from 'axios'; import APIService from './api-service'; export default class AppConfigService extends APIService { @@ -56,12 +56,23 @@ export default class AppConfigService extends APIService { } async getVersionInformation() { - const response = ( - await axios.get('https://api.github.com/repos/stonith404/pocket-id/releases/latest') - ).data; + const response = await axios + .get('https://api.github.com/repos/stonith404/pocket-id/releases/latest') + .then((res) => res.data) + .catch((e) => { + console.error( + 'Failed to fetch version information', + e instanceof AxiosError && e.response ? e.response.data.message : e + ); + return null; + }); - const newestVersion = response.tag_name.replace('v', ''); - const isUpToDate = newestVersion === currentVersion; + let newestVersion: string | null = null; + let isUpToDate: boolean | null = null; + if (response) { + newestVersion = response.tag_name.replace('v', ''); + isUpToDate = newestVersion === currentVersion; + } return { isUpToDate, diff --git a/frontend/src/lib/types/application-configuration.ts b/frontend/src/lib/types/application-configuration.ts index 76a68e9..ea8f08a 100644 --- a/frontend/src/lib/types/application-configuration.ts +++ b/frontend/src/lib/types/application-configuration.ts @@ -41,7 +41,7 @@ export type AppConfigRawResponse = { }[]; export type AppVersionInformation = { - isUpToDate: boolean; - newestVersion: string; - currentVersion: string; + isUpToDate: boolean | null; + newestVersion: string | null; + currentVersion: string }; diff --git a/frontend/src/routes/settings/+layout.server.ts b/frontend/src/routes/settings/+layout.server.ts index 2203fdc..c50c44c 100644 --- a/frontend/src/routes/settings/+layout.server.ts +++ b/frontend/src/routes/settings/+layout.server.ts @@ -15,6 +15,9 @@ export const load: LayoutServerLoad = async () => { if (!versionInformation || cacheExpired) { versionInformation = await appConfigService.getVersionInformation(); + if (versionInformation.newestVersion == null) { + console.error('Failed to fetch version information. Trying again in 3 hours.'); + } versionInformationLastUpdated = Date.now(); } diff --git a/frontend/src/routes/settings/+layout.svelte b/frontend/src/routes/settings/+layout.svelte index 13f8d64..9bad1e3 100644 --- a/frontend/src/routes/settings/+layout.svelte +++ b/frontend/src/routes/settings/+layout.svelte @@ -50,7 +50,7 @@ {label} {/each} - {#if $userStore?.isAdmin && !versionInformation.isUpToDate} + {#if $userStore?.isAdmin && versionInformation.isUpToDate === false}