Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] - Be more robust against fiat queries errors for source 1 #523

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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