Sha256: 7775970bc10b4dd649e2afa148434b355e868acb761ec05739273b251271b60f

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module Centro
  module API
    module Base

      def mms(method, *args)
        mms_connection.send(method, *args)
      rescue Exception => e
        raise adapt_error(e)
      end

      def finance(method, *args)
        finance_connection.send(method, *args)
      rescue Exception => e
        raise adapt_error(e)
      end

      def auth(method, *args)
        auth_connection.send(method, *args)
      rescue Exception => e
        raise adapt_error(e)
      end

      private

      def adapt_error(e)
        case e
        when Faraday::Error::ConnectionFailed
          Centro::Error::ConnectionFailed.new(e, e.response)
        when Faraday::Error::ResourceNotFound
          Centro::Error::ResourceNotFound.new(e, e.response)
        when Faraday::Error::ParsingError
          Centro::Error::ParsingError.new(e, e.response)
        when Faraday::Error::TimeoutError
          Centro::Error::TimeoutError.new(e, e.response)
        else
          Centro::Error::ClientError.new(e)
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
centro-client-0.0.3 lib/centro/api/base.rb