diff --git a/CHANGELOG.md b/CHANGELOG.md index efd1cda0e..829c52612 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +- Added a fallback if the exchange rate service has not been initialized correctly + +## Unreleased + ### Changed - Hid the pagination of tabs diff --git a/apps/api/src/services/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data.service.ts index 0d5f67870..6f2b71196 100644 --- a/apps/api/src/services/exchange-rate-data.service.ts +++ b/apps/api/src/services/exchange-rate-data.service.ts @@ -2,6 +2,7 @@ import { DATE_FORMAT, getYesterday } from '@ghostfolio/common/helper'; import { Injectable } from '@nestjs/common'; import { Currency } from '@prisma/client'; import { format } from 'date-fns'; +import { isNumber } from 'lodash'; import { DataProviderService } from './data-provider.service'; @@ -83,7 +84,15 @@ export class ExchangeRateDataService { factor = this.currencies[`${aFromCurrency}${aToCurrency}`]; } - return factor * aValue; + if (isNumber(factor)) { + return factor * aValue; + } + + // Fallback with error, if currencies are not available + console.error( + `No exchange rate has been found for ${aFromCurrency}${aToCurrency}` + ); + return aValue; } private addPairs(aCurrency1: Currency, aCurrency2: Currency) {