From 1a247d6e97dccbe9ff4365c5c7d8ef735eb20d59 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 24 May 2025 19:51:45 +0100 Subject: [PATCH] Feature/improve handling of schema validation errors in search of Yahoo Finance service (#4744) * Improve handling of schema validation errors * Update changelog --- CHANGELOG.md | 1 + .../yahoo-finance/yahoo-finance.service.ts | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34d84a3cc..7d2570eb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Increased the robustness of the search in the _Yahoo Finance_ service by catching schema validation errors - Improved the symbol lookup results by removing the currency from the name of cryptocurrencies (experimental) - Harmonized the data providers management style of the admin control panel - Extended the data providers management of the admin control panel by the asset profile count diff --git a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts index d5a132b41..06e4674fb 100644 --- a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts +++ b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts @@ -30,8 +30,11 @@ import { HistoricalDividendsResult, HistoricalHistoryResult } from 'yahoo-finance2/esm/src/modules/historical'; -import { Quote } from 'yahoo-finance2/esm/src/modules/quote'; -import { SearchQuoteNonYahoo } from 'yahoo-finance2/script/src/modules/search'; +import { + Quote, + QuoteResponseArray +} from 'yahoo-finance2/esm/src/modules/quote'; +import { SearchQuoteNonYahoo } from 'yahoo-finance2/esm/src/modules/search'; @Injectable() export class YahooFinanceService implements DataProviderInterface { @@ -281,11 +284,19 @@ export class YahooFinanceService implements DataProviderInterface { return true; }); - const marketData = await this.yahooFinance.quote( - quotes.map(({ symbol }) => { - return symbol; - }) - ); + let marketData: QuoteResponseArray = []; + + try { + marketData = await this.yahooFinance.quote( + quotes.map(({ symbol }) => { + return symbol; + }) + ); + } catch (error) { + if (error?.result?.length > 0) { + marketData = error.result; + } + } for (const marketDataItem of marketData) { const quote = quotes.find((currentQuote) => {