Skip to content

Commit

Permalink
refactor: server.version must be present
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Sep 29, 2023
1 parent 1eae1fb commit 99d5f5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/constants/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
20 changes: 6 additions & 14 deletions src/context/ServiceInfoContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type SessionInfo = {
}
type ServerInfo = {
server?: {
version?: SemVer
version: SemVer
}
}

Expand Down Expand Up @@ -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 },
})
}
})
Expand Down

0 comments on commit 99d5f5c

Please sign in to comment.