Sha256: a7aacce9363c2bb205e34f42013eb4742eb343814a733e63804373ab0b5ce653

Contents?: true

Size: 1.86 KB

Versions: 13

Compression:

Stored size: 1.86 KB

Contents

module Socialcastr
  class InvalidMethod < StandardError; end
  class InvalidAttribute < StandardError; end
  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:

  # 422 Invalid
  class ResourceInvalid < 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

13 entries across 13 versions & 1 rubygems

Version Path
socialcastr-0.2.18 lib/socialcastr/exceptions.rb
socialcastr-0.2.17 lib/socialcastr/exceptions.rb
socialcastr-0.2.16 lib/socialcastr/exceptions.rb
socialcastr-0.2.15 lib/socialcastr/exceptions.rb
socialcastr-0.2.14 lib/socialcastr/exceptions.rb
socialcastr-0.2.13 lib/socialcastr/exceptions.rb
socialcastr-0.2.12 lib/socialcastr/exceptions.rb
socialcastr-0.2.11 lib/socialcastr/exceptions.rb
socialcastr-0.2.10 lib/socialcastr/exceptions.rb
socialcastr-0.2.9 lib/socialcastr/exceptions.rb
socialcastr-0.2.8 lib/socialcastr/exceptions.rb
socialcastr-0.2.7 lib/socialcastr/exceptions.rb
socialcastr-0.2.6 lib/socialcastr/exceptions.rb