diff --git a/openvidu-call-front/src/app/core/services/config.service.ts b/openvidu-call-front/src/app/core/services/config.service.ts index 898f5d2a..fa8477be 100644 --- a/openvidu-call-front/src/app/core/services/config.service.ts +++ b/openvidu-call-front/src/app/core/services/config.service.ts @@ -5,10 +5,10 @@ import { HttpService } from '@services/http.service'; providedIn: 'root' }) export class ConfigService { - private config: { isPrivate: boolean }; - private initialization: Promise; + private config: { isPrivate: boolean } | undefined; + private initialization: Promise | undefined; - constructor(private restService: HttpService) {} + constructor(private httpService: HttpService) {} async initialize(): Promise { if (!this.initialization) { @@ -19,10 +19,21 @@ export class ConfigService { } private async loadConfig(): Promise { - this.config = await this.restService.getConfig(); + try { + this.config = await this.httpService.getConfig(); + } catch (error) { + console.error('Failed to load configuration:', error); + // Handle the error as needed, e.g., set default config or notify the user + this.config = { isPrivate: true }; // Default value in case of error + } } isPrivateAccess(): boolean { + // Ensure configuration is loaded before accessing it + if (!this.initialization) { + throw new Error('ConfigService not initialized. Call initialize() before accessing config.'); + } + return this.config?.isPrivate ?? true; } }