Skip to content

Commit

Permalink
Improve exception handling to match Codacy rules
Browse files Browse the repository at this point in the history
Rewrite a few generic parts of the code to be more specific in what they
 handle, or how they handle the resulting data structure.
  • Loading branch information
cd2357 committed Aug 8, 2020
1 parent 0c27038 commit d972a75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.knowm.xchange.currency.Currency;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.marketdata.Ticker;
import org.knowm.xchange.exceptions.ExchangeException;
import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException;
import org.knowm.xchange.service.marketdata.MarketDataService;
import org.knowm.xchange.service.marketdata.params.CurrencyPairsParam;
Expand Down Expand Up @@ -210,8 +211,13 @@ public Collection<CurrencyPair> getCurrencyPairs() {
log.error("Could not query tickers for " + getName(), e);
}
});
}
catch (Exception e) {
} catch (ExchangeException | // Errors reported by the exchange (rate limit, etc)
IOException | // Errors while trying to connect to the API (timeouts, etc)
// Potential error when integrating new exchange (hints that exchange
// provider implementation needs to overwrite
// requiresFilterDuringBulkTickerRetrieval() and have it return true )
IllegalArgumentException e) {
// Catch and handle all other possible exceptions
// If there was a problem with polling this exchange, return right away,
// since there are no results to parse and process
log.error("Could not query tickers for provider " + getName(), e);
Expand All @@ -236,8 +242,7 @@ public Collection<CurrencyPair> getCurrencyPairs() {
String otherExchangeRateCurrency;
if (t.getCurrencyPair().base.equals(Currency.BTC)) {
otherExchangeRateCurrency = t.getCurrencyPair().counter.getCurrencyCode();
}
else {
} else {
otherExchangeRateCurrency = t.getCurrencyPair().base.getCurrencyCode();
}

Expand Down
17 changes: 9 additions & 8 deletions pricenode/src/main/java/bisq/price/spot/ExchangeRateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ public Map<String, Object> getAllMarketPrices() {
metadata.putAll(getMetadata(p, exchangeRates));
});

return new LinkedHashMap<String, Object>() {{
putAll(metadata);
// Use a sorted list by currency code to make comparision of json data between
// different price nodes easier
List<ExchangeRate> values = new ArrayList<>(aggregateExchangeRates.values());
values.sort(Comparator.comparing(ExchangeRate::getCurrency));
put("data", values);
}};
LinkedHashMap<String, Object> result = new LinkedHashMap<>();
result.putAll(metadata);
// Use a sorted list by currency code to make comparision of json data between
// different price nodes easier
List<ExchangeRate> values = new ArrayList<>(aggregateExchangeRates.values());
values.sort(Comparator.comparing(ExchangeRate::getCurrency));
result.put("data", values);

return result;
}

/**
Expand Down

0 comments on commit d972a75

Please sign in to comment.