Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
fix(converter): fix confusing error returning now rate
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Mar 2, 2019
1 parent b4ba88d commit 291f91e
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions back/src/money/application/CurrencyConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,13 @@ export class CurrencyConverter {
): Promise<number> {
const MIN_DAY_FOR_HISTORY_TRANSACTION = 2

const rateIsHistory =
const rateIsOld =
differenceInDays(when, new Date()) > MIN_DAY_FOR_HISTORY_TRANSACTION

const getNowRate = () => this.exchangeRateApi.getExchangeRate(from, to)

const getHistoryRate = () =>
this.exchangeRateApi
.getHistoryExchangeRate(from, to, when)
.catch(getNowRate) // Okay, now rate is ok
if (rateIsOld) {
return this.exchangeRateApi.getHistoryExchangeRate(from, to, when)
}

return rateIsHistory ? getNowRate() : getHistoryRate()
return this.exchangeRateApi.getExchangeRate(from, to)
}
}

0 comments on commit 291f91e

Please sign in to comment.