Prevent from using variables before initialization on connection (#3702)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov 2023-09-15 13:32:53 +05:00 committed by GitHub
parent 2d16709ccb
commit 538f95f94c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,7 +64,10 @@ export async function connect (title: string): Promise<Client | undefined> {
let clientSet = false
let version: Version | undefined
let serverEndpoint = endpoint.replace(/^ws/g, 'http')
if (serverEndpoint.endsWith('/')) {
serverEndpoint = serverEndpoint.substring(0, serverEndpoint.length - 1)
}
const clientFactory = await getResource(client.function.GetClient)
_client = await clientFactory(
token,
@ -87,7 +90,8 @@ export async function connect (title: string): Promise<Client | undefined> {
}
void (async () => {
const newVersion = await _client?.findOne<Version>(core.class.Version, {})
if (_client !== undefined) {
const newVersion = await _client.findOne<Version>(core.class.Version, {})
console.log('Reconnect Model version', newVersion)
const currentVersionStr = versionToString(version as Version)
@ -97,7 +101,9 @@ export async function connect (title: string): Promise<Client | undefined> {
// It seems upgrade happened
location.reload()
}
const serverVersion: { version: string } = await (await fetch(serverEndpoint + '/api/v1/version', {})).json()
const serverVersion: { version: string } = await (
await fetch(serverEndpoint + '/api/v1/version', {})
).json()
console.log('Server version', serverVersion.version)
if (serverVersion.version !== '' && serverVersion.version !== currentVersionStr) {
@ -106,6 +112,7 @@ export async function connect (title: string): Promise<Client | undefined> {
window.location.reload()
}, 5000)
}
}
})()
} catch (err) {
console.error(err)
@ -131,12 +138,6 @@ export async function connect (title: string): Promise<Client | undefined> {
clientSet = true
return
}
let serverEndpoint = endpoint.replace(/^ws/g, 'http')
if (serverEndpoint.endsWith('/')) {
serverEndpoint = serverEndpoint.substring(0, serverEndpoint.length - 1)
}
try {
version = await _client.findOne<Version>(core.class.Version, {})
console.log('Model version', version)