Skip to content

Commit

Permalink
[Feature] - Be more robust against fiat queries errors for source 1
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanel committed Mar 7, 2024
1 parent 4d12e3e commit 80f1199
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/api/common/src/commonapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ vector<CurrencyCode> 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() &&
Expand Down
2 changes: 1 addition & 1 deletion src/api/common/src/fiatconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ std::optional<double> 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;
Expand Down

0 comments on commit 80f1199

Please sign in to comment.