From a9fbb5d689e9f9c563f0dc799a7d184526c9d17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Beaupre=CC=81?= Date: Mon, 14 Feb 2022 20:16:20 +0100 Subject: [PATCH] Fix: Error handling --- lib/money/bank/currencylayer_bank.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/money/bank/currencylayer_bank.rb b/lib/money/bank/currencylayer_bank.rb index 0092ca3..7203e59 100644 --- a/lib/money/bank/currencylayer_bank.rb +++ b/lib/money/bank/currencylayer_bank.rb @@ -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