diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b1f613e9..f2113955c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the usability of the platform management in the admin control panel - Improved the usability of the tag management in the admin control panel +- Improved the exception handling of various rules in the _X-ray_ section ### Fixed diff --git a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts index 23d3307de..52f20a218 100644 --- a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts +++ b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts @@ -35,7 +35,7 @@ export class AccountClusterRiskCurrentInvestment extends Rule { }; } - let maxItem; + let maxItem: (typeof accounts)[0]; let totalInvestment = 0; for (const account of Object.values(accounts)) { @@ -52,7 +52,7 @@ export class AccountClusterRiskCurrentInvestment extends Rule { } } - const maxInvestmentRatio = maxItem.investment / totalInvestment; + const maxInvestmentRatio = maxItem?.investment / totalInvestment || 0; if (maxInvestmentRatio > ruleSettings.threshold) { return { diff --git a/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts index a23a208c3..a2bd44f44 100644 --- a/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts +++ b/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts @@ -43,7 +43,7 @@ export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule { } }); - const maxValueRatio = maxItem.value / totalValue; + const maxValueRatio = maxItem?.value / totalValue || 0; if (maxValueRatio > ruleSettings.threshold) { return { @@ -52,7 +52,7 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule { return { evaluation: `The major part of your current investment is in ${ - maxItem.groupKey + maxItem?.groupKey ?? ruleSettings.baseCurrency } (${(maxValueRatio * 100).toPrecision(3)}%) and does not exceed ${ ruleSettings.threshold * 100 }%`,