Sha256: 83a3a30fae65318381a5a274cbafd6c6634cd0d8f195cd3f7d2a0eee763bd8d6

Contents?: true

Size: 1.72 KB

Versions: 42

Compression:

Stored size: 1.72 KB

Contents

module Tickethub
  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 << "  Response Body = #{response.body}." if response.respond_to?(:body)
      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:

  # 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

42 entries across 42 versions & 1 rubygems

Version Path
tickethub-0.3.30 lib/tickethub/exceptions.rb
tickethub-0.3.29 lib/tickethub/exceptions.rb
tickethub-0.3.28 lib/tickethub/exceptions.rb
tickethub-0.3.27 lib/tickethub/exceptions.rb
tickethub-0.3.26 lib/tickethub/exceptions.rb
tickethub-0.3.25 lib/tickethub/exceptions.rb
tickethub-0.3.24 lib/tickethub/exceptions.rb
tickethub-0.3.23 lib/tickethub/exceptions.rb
tickethub-0.3.22 lib/tickethub/exceptions.rb
tickethub-0.3.21 lib/tickethub/exceptions.rb
tickethub-0.3.20 lib/tickethub/exceptions.rb
tickethub-0.3.18 lib/tickethub/exceptions.rb
tickethub-0.3.17 lib/tickethub/exceptions.rb
tickethub-0.3.16 lib/tickethub/exceptions.rb
tickethub-0.3.15 lib/tickethub/exceptions.rb
tickethub-0.3.14 lib/tickethub/exceptions.rb
tickethub-0.3.13 lib/tickethub/exceptions.rb
tickethub-0.3.12 lib/tickethub/exceptions.rb
tickethub-0.3.11 lib/tickethub/exceptions.rb
tickethub-0.3.9 lib/tickethub/exceptions.rb