From 0fcfa6c1bd3e98bfa897237eada33c8e192ed6bd Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 10 Sep 2022 18:58:31 +0200 Subject: [PATCH] Bugfix/improve error handling in benchmark calculation (#1246) * Improve error handling * Update changelog --- CHANGELOG.md | 4 ++++ apps/api/src/app/benchmark/benchmark.service.ts | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 916edcdb5..c6f5db1c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Upgraded `yahoo-finance2` from version `2.3.3` to `2.3.6` +### Fixed + +- Improved the error handling in the benchmark calculation + ## 1.191.0 - 10.09.2022 ### Changed diff --git a/apps/api/src/app/benchmark/benchmark.service.ts b/apps/api/src/app/benchmark/benchmark.service.ts index 7987cb5b9..71337c6ab 100644 --- a/apps/api/src/app/benchmark/benchmark.service.ts +++ b/apps/api/src/app/benchmark/benchmark.service.ts @@ -31,7 +31,11 @@ export class BenchmarkService { ) {} public calculateChangeInPercentage(baseValue: number, currentValue: number) { - return new Big(currentValue).div(baseValue).minus(1).toNumber(); + if (baseValue && currentValue) { + return new Big(currentValue).div(baseValue).minus(1).toNumber(); + } + + return 0; } public async getBenchmarks({ useCache = true } = {}): Promise<