Skip to content

Commit

Permalink
Merge pull request #9 from hrdwdmrbl/master
Browse files Browse the repository at this point in the history
Fix: Error handling.
  • Loading branch information
phlegx authored Feb 15, 2022
2 parents 43db98e + a9fbb5d commit 470f73f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/money/bank/currencylayer_bank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,18 @@ def valid_rates?(text)
# @param straight [Boolean] true for straight, default is careful
# @return [Hash] key is country code (ISO 3166-1 alpha-3) value Float
def exchange_rates(straight = false)
@rates = if straight
raw_rates_straight['quotes']
else
raw_rates_careful['quotes']
end
rates = if straight
raw_rates_straight
else
raw_rates_careful
end
if rates.key?('quotes')
@rates = rates['quotes']
elsif rates.key?('error')
raise Error.new(rates.dig('error', 'info'))
else
raise Error.new('Unknown situation')
end
end

# Get raw exchange rates from cache and then from url
Expand Down

0 comments on commit 470f73f

Please sign in to comment.