Sha256: 4f5ff80c0a3a97df78bf85afe085fbc486c8447c62a254b50c73e190380bb4e9

Contents?: true

Size: 645 Bytes

Versions: 4

Compression:

Stored size: 645 Bytes

Contents

module Rainforest
  class ApiError < RainforestError
    attr_reader :api_method

    def initialize(message=nil, api_method=nil)
      @message = message
      @api_method = api_method
    end

    def code
      @api_method.response_code if @api_method
    end

    def body
      @api_method.response_body if @api_method
    end

    def json
      begin
        if @api_method
          hash = @api_method.response_json
          return ApiObject.construct(hash)
        end
      rescue ApiError
        nil
      end
    end

    def to_s
      prefix = code.nil? ? "" : "(Status #{code}) "
      "#{prefix}#{@message}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rainforest-2.1.0 lib/rainforest/errors/api_error.rb
rainforest-2.0.2 lib/rainforest/errors/api_error.rb
rainforest-2.0.1 lib/rainforest/errors/api_error.rb
rainforest-2.0.0 lib/rainforest/errors/api_error.rb