more fixes

This commit is contained in:
Andras Schmelczer 2026-04-25 20:42:34 +01:00
parent 8ce33541a3
commit 7a8c497462
6 changed files with 94 additions and 38 deletions

View file

@ -14,15 +14,14 @@ export class ServerConfig {
private response: Promise<PingResponse> | undefined;
private config: ServerConfigData | undefined;
public constructor(private readonly syncService: SyncService) {}
public constructor(private readonly syncService: SyncService) { }
private static validateConfig(config: ServerConfigData): void {
if (config.supportedApiVersion !== SUPPORTED_API_VERSION) {
const shouldUpgradeClient =
config.supportedApiVersion > SUPPORTED_API_VERSION;
throw new ServerVersionMismatchError(
`Unsupported API version: ${config.supportedApiVersion}. Consider upgrading the ${
shouldUpgradeClient ? "client" : "sync-server"
`Unsupported API version: ${config.supportedApiVersion}. Consider upgrading the ${shouldUpgradeClient ? "client" : "sync-server"
} to ensure compatibility`
);
}
@ -41,7 +40,7 @@ export class ServerConfig {
try {
let { response } = this;
if (!response || forceUpdate) {
response = this.response = this.syncService.ping();
response = this.startPing();
}
const result: PingResponse = await response; // it must be defined, otherwise we would have thrown above
@ -68,7 +67,7 @@ export class ServerConfig {
public async getConfig(): Promise<ServerConfigData> {
if (!this.config) {
this.response ??= this.syncService.ping();
this.response ??= this.startPing();
this.config = await this.response;
}
@ -77,6 +76,17 @@ export class ServerConfig {
return this.config;
}
private startPing(): Promise<PingResponse> {
const pending = this.syncService.ping().catch((e: unknown) => {
if (this.response === pending) {
this.response = undefined;
}
throw e;
});
this.response = pending;
return pending;
}
public reset(): void {
this.response = undefined;
this.config = undefined;