dblock / iex-ruby-client

IEX Finance API Ruby Client
MIT License
119 stars 60 forks source link

Translate Faraday::ClientError into IEX::Errors::ClientError everywhere #15

Closed dblock closed 6 years ago

dblock commented 6 years ago

We now handle Faraday::ClientError differently in Chart#get than in all the other calls. Error handling should be moved into the base class and handled consistently everywhere.

@rodolfobandeira

Add a module ala

module IEX::Resources::Base
   def self.symbol(symbol, &_block)
      yield
     rescue Faraday::ResourceNotFound => e
        raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
      rescue Faraday::ClientError => e
        raise IEX::Errors::ClientError, e.response
      end
   end

Then extend other modules with it and use symbol do ... everywhere instead of explicitly rescue-ing exceptions.

rodolfobandeira commented 6 years ago

Believe or not, I thought the same while writing the upgrade docs. A PR should be coming soon.