2009-05-06 03:14:55 -04:00
|
|
|
module ActiveResource
|
|
|
|
class ConnectionError < StandardError # :nodoc:
|
|
|
|
attr_reader :response
|
|
|
|
|
|
|
|
def initialize(response, message = nil)
|
|
|
|
@response = response
|
|
|
|
@message = message
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2009-10-04 04:50:47 -04:00
|
|
|
message = "Failed."
|
|
|
|
message << " Response code = #{response.code}." if response.respond_to?(:code)
|
|
|
|
message << " Response message = #{response.message}." if response.respond_to?(:message)
|
|
|
|
message
|
2009-05-06 03:14:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Raised when a Timeout::Error occurs.
|
|
|
|
class TimeoutError < ConnectionError
|
|
|
|
def initialize(message)
|
|
|
|
@message = message
|
|
|
|
end
|
|
|
|
def to_s; @message ;end
|
|
|
|
end
|
|
|
|
|
2009-08-09 13:57:20 -04:00
|
|
|
# Raised when a OpenSSL::SSL::SSLError occurs.
|
|
|
|
class SSLError < ConnectionError
|
|
|
|
def initialize(message)
|
|
|
|
@message = message
|
|
|
|
end
|
|
|
|
def to_s; @message ;end
|
|
|
|
end
|
|
|
|
|
2009-05-06 03:14:55 -04:00
|
|
|
# 3xx Redirection
|
|
|
|
class Redirection < ConnectionError # :nodoc:
|
|
|
|
def to_s; response['Location'] ? "#{super} => #{response['Location']}" : super; end
|
|
|
|
end
|
|
|
|
|
2010-09-13 16:05:52 -04:00
|
|
|
# Raised when ...
|
|
|
|
class MissingPrefixParam < ArgumentError; end # :nodoc:
|
|
|
|
|
2009-05-06 03:14:55 -04:00
|
|
|
# 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:
|
|
|
|
|
2009-08-09 17:53:04 -04:00
|
|
|
# 410 Gone
|
|
|
|
class ResourceGone < ClientError; end # :nodoc:
|
|
|
|
|
2009-05-06 03:14:55 -04:00
|
|
|
# 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
|