From 80f119932c81733787d2677a5edc1958f212b6ba Mon Sep 17 00:00:00 2001 From: Stephane Janel Date: Wed, 6 Mar 2024 23:52:39 +0100 Subject: [PATCH] [Feature] - Be more robust against fiat queries errors for source 1 --- src/api/common/src/commonapi.cpp | 8 +++++++- src/api/common/src/fiatconverter.cpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/api/common/src/commonapi.cpp b/src/api/common/src/commonapi.cpp index dd0be7d2..13a2063d 100644 --- a/src/api/common/src/commonapi.cpp +++ b/src/api/common/src/commonapi.cpp @@ -98,10 +98,16 @@ vector CommonAPI::FiatsFunc::retrieveFiatsSource1() { log::error("Error parsing currency codes, no fiats found from first source"); return fiatsVec; } - json dataCSV = json::parse(data); + static constexpr bool kAllowExceptions = false; + json dataCSV = json::parse(data, nullptr, kAllowExceptions); + if (dataCSV.is_discarded()) { + log::error("Error parsing json data of currency codes from source 1"); + return fiatsVec; + } for (const json& fiatData : dataCSV) { static constexpr std::string_view kCodeKey = "AlphabeticCode"; static constexpr std::string_view kWithdrawalDateKey = "WithdrawalDate"; + auto codeIt = fiatData.find(kCodeKey); auto withdrawalDateIt = fiatData.find(kWithdrawalDateKey); if (codeIt != fiatData.end() && !codeIt->is_null() && withdrawalDateIt != fiatData.end() && diff --git a/src/api/common/src/fiatconverter.cpp b/src/api/common/src/fiatconverter.cpp index f163b341..bf94a278 100644 --- a/src/api/common/src/fiatconverter.cpp +++ b/src/api/common/src/fiatconverter.cpp @@ -108,7 +108,7 @@ std::optional FiatConverter::queryCurrencyRateSource1(Market mk) { //{"query":{"count":1},"results":{"EUR_KRW":{"id":"EUR_KRW","val":1329.475323,"to":"KRW","fr":"EUR"}}} const auto resultsIt = data.find("results"); - if (data == json::value_t::discarded || resultsIt == data.end() || !resultsIt->contains(qStr)) { + if (data.is_discarded() || resultsIt == data.end() || !resultsIt->contains(qStr)) { log::warn("No JSON data received from fiat currency converter service's first source for pair '{}'", mk); refreshLastUpdatedTime(mk); return std::nullopt;