From d8bc93a085911adf1ea1c5edf45ddcecc1f42af8 Mon Sep 17 00:00:00 2001 From: TaprootFreak <142087526+TaprootFreak@users.noreply.github.com> Date: Tue, 12 May 2026 22:26:16 +0200 Subject: [PATCH] fix(pricing): await currencies load in CoinGeckoService.onModuleInit The onModuleInit method used void-promise pattern, leaving this.currencies undefined until the async call resolved. If MonitoringService cron fired before that (which it does on container start), getCurrency() crashed with "Cannot read properties of undefined (reading 'find')". Make onModuleInit properly async with try/catch to preserve original resilience (CoinGecko outage at startup should not crash app startup) while adding error logging. --- src/subdomains/pricing/services/coingecko.service.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/subdomains/pricing/services/coingecko.service.ts b/src/subdomains/pricing/services/coingecko.service.ts index 8fdcd09e2..89df03f06 100644 --- a/src/subdomains/pricing/services/coingecko.service.ts +++ b/src/subdomains/pricing/services/coingecko.service.ts @@ -9,14 +9,18 @@ export class CoinGeckoService implements OnModuleInit { private readonly logger = new LightningLogger(CoinGeckoService); private readonly client: CoinGeckoClient; - private currencies: string[]; + private currencies: string[] = []; constructor() { this.client = new CoinGeckoClient({ autoRetry: false }, GetConfig().coinGecko.apiKey); } - onModuleInit() { - void this.client.simpleSupportedCurrencies().then((cs) => (this.currencies = cs)); + async onModuleInit(): Promise { + try { + this.currencies = await this.client.simpleSupportedCurrencies(); + } catch (e) { + this.logger.error('Failed to load CoinGecko currencies on startup', e); + } } async getPrice(from: string, to: string): Promise {