Sha256: 35ebf1b21790a992e49844fd59e3e626a863ee171f5efd9da1ea670bfa6213f9

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 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

      def planner(method, *args)
        planner_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.4 lib/centro/api/base.rb