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 23, 2023
1 parent 34d1963 commit 4d61119
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 @@ -81,7 +81,7 @@ type SessionInfo = {
}
type ServerInfo = {
server?: {
version?: SemVer
version: SemVer
}
}

Expand Down Expand Up @@ -134,20 +134,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),
},
})
})
.catch((err) => {
const notFound = err.response.status === 404
if (notFound) {
.then((data: JmGetInfoData) => toSemVer(data))
.catch((_) => UNKNOWN_VERSION)
.then((version) => {
if (!abortCtrl.signal.aborted) {
dispatchServiceInfo({
server: {
version: UNKNOWN_VERSION,
},
server: { version },
})
}
})
Expand Down

0 comments on commit 4d61119

Please sign in to comment.