Sha256: 6778d42c4e05df4ab5c10553886a2d7044882197d0f7f44f1785fc2fc23e591e

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

class HyperResource
  class Exception < ::StandardError
    ## The internal exception which led to this one, if any.
    attr_accessor :cause

    # @private
    def initialize(message, attrs={})
      self.cause = attrs[:cause]
      super(message)
    end
  end

  class ResponseError < Exception
    ## The +Faraday::Response+ object which led to this exception.
    attr_accessor :response

    ## The deserialized response body which led to this exception.
    ## May be blank, e.g. in case of deserialization errors.
    attr_accessor :body

    # @private
    def initialize(message, attrs={})
      self.response = attrs[:response]
      self.body = attrs[:body]

      ## Try to help out with the message
      if self.body
        if error = self.body['error']
          message = "#{message} (#{error})"
        end
      elsif self.response
        message = "#{message} (\"#{self.response.inspect}\")"
      end

      super(message, attrs)
    end
  end

  class ClientError < ResponseError; end
  class ServerError < ResponseError; end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
hyperresource-0.9.4 lib/hyper_resource/exceptions.rb
hyperresource-0.9.3 lib/hyper_resource/exceptions.rb
hyperresource-0.9.2 lib/hyper_resource/exceptions.rb
hyperresource-0.9.1 lib/hyper_resource/exceptions.rb
hyperresource_zuhrig-0.1.0 lib/hyper_resource/exceptions.rb
hyperresource-0.9.0 lib/hyper_resource/exceptions.rb