Sha256: c123cf5108a322f67e4208176722fc4a080f0fad0522281c7ebbbfc1e9d0f96a

Contents?: true

Size: 1.7 KB

Versions: 44

Compression:

Stored size: 1.7 KB

Contents

module ActiveResource
  class ConnectionError < StandardError # :nodoc:
    attr_reader :response

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

    def to_s
      message = "Failed."
      message << "  Response code = #{response.code}." if response.respond_to?(:code)
      message << "  Response message = #{response.message}." if response.respond_to?(:message)
      message
    end
  end

  # Raised when a Timeout::Error occurs.
  class TimeoutError < ConnectionError
    def initialize(message)
      @message = message
    end
    def to_s; @message ;end
  end

  # Raised when a OpenSSL::SSL::SSLError occurs.
  class SSLError < ConnectionError
    def initialize(message)
      @message = message
    end
    def to_s; @message ;end
  end

  # 3xx Redirection
  class Redirection < ConnectionError # :nodoc:
    def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end
  end

  # 4xx Client Error
  class ClientError < ConnectionError; end # :nodoc:

  # 400 Bad Request
  class BadRequest < ClientError; end # :nodoc

  # 401 Unauthorized
  class UnauthorizedAccess < ClientError; end # :nodoc

  # 403 Forbidden
  class ForbiddenAccess < ClientError; end # :nodoc

  # 404 Not Found
  class ResourceNotFound < ClientError; end # :nodoc:

  # 409 Conflict
  class ResourceConflict < ClientError; end # :nodoc:

  # 410 Gone
  class ResourceGone < ClientError; end # :nodoc:

  # 5xx Server Error
  class ServerError < ConnectionError; end # :nodoc:

  # 405 Method Not Allowed
  class MethodNotAllowed < ClientError # :nodoc:
    def allowed_methods
      @response['Allow'].split(',').map { |verb| verb.strip.downcase.to_sym }
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
activeresource-3.0.20 lib/active_resource/exceptions.rb
activeresource-3.0.19 lib/active_resource/exceptions.rb
activeresource-3.0.18 lib/active_resource/exceptions.rb
activeresource-3.0.17 lib/active_resource/exceptions.rb
activeresource-3.0.16 lib/active_resource/exceptions.rb
activeresource-3.0.15 lib/active_resource/exceptions.rb
activeresource-3.0.14 lib/active_resource/exceptions.rb
activeresource-3.0.13 lib/active_resource/exceptions.rb
activeresource-3.0.13.rc1 lib/active_resource/exceptions.rb
activeresource-3.0.12 lib/active_resource/exceptions.rb
activeresource-3.0.12.rc1 lib/active_resource/exceptions.rb
activeresource-3.0.11 lib/active_resource/exceptions.rb
activeresource-3.0.10 lib/active_resource/exceptions.rb
activeresource-3.0.10.rc1 lib/active_resource/exceptions.rb
activeresource-3.0.9 lib/active_resource/exceptions.rb
activeresource-3.0.9.rc5 lib/active_resource/exceptions.rb
activeresource-3.0.9.rc4 lib/active_resource/exceptions.rb
activeresource-3.0.9.rc3 lib/active_resource/exceptions.rb
activeresource-3.0.9.rc1 lib/active_resource/exceptions.rb
activeresource-3.0.8 lib/active_resource/exceptions.rb