From 99d5f5cf6083b538247a95eeebb81b058a9cf379 Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Fri, 22 Sep 2023 19:07:45 +0200 Subject: [PATCH] refactor: server.version must be present --- src/constants/features.ts | 2 +- src/context/ServiceInfoContext.tsx | 20 ++++++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/constants/features.ts b/src/constants/features.ts index d0ea91144..236fc6c39 100644 --- a/src/constants/features.ts +++ b/src/constants/features.ts @@ -22,5 +22,5 @@ const __isFeatureEnabled = (name: Feature, version: SemVer): boolean => { } export const isFeatureEnabled = (name: Feature, serviceInfo: ServiceInfo): boolean => { - return !!serviceInfo.server?.version && __isFeatureEnabled(name, serviceInfo.server.version) + return !!serviceInfo.server && __isFeatureEnabled(name, serviceInfo.server.version) } diff --git a/src/context/ServiceInfoContext.tsx b/src/context/ServiceInfoContext.tsx index 3fe4cfb8b..d84c0de08 100644 --- a/src/context/ServiceInfoContext.tsx +++ b/src/context/ServiceInfoContext.tsx @@ -80,7 +80,7 @@ type SessionInfo = { } type ServerInfo = { server?: { - version?: SemVer + version: SemVer } } @@ -118,20 +118,12 @@ const ServiceInfoProvider = ({ children }: PropsWithChildren<{}>) => { Api.getGetinfo({ signal: abortCtrl.signal }) .then((res) => (res.ok ? res.json() : Api.Helper.throwError(res))) - .then((data: JmGetInfoData) => { - dispatchServiceInfo({ - server: { - version: toSemVer(data.version), - }, - }) - }) - .catch((err) => { - const notFound = err.response.status === 404 - if (notFound) { + .then((data: JmGetInfoData) => toSemVer(data.version)) + .catch((_) => UNKNOWN_VERSION) + .then((version) => { + if (!abortCtrl.signal.aborted) { dispatchServiceInfo({ - server: { - version: UNKNOWN_VERSION, - }, + server: { version }, }) } })