Sha256: 5cb9d087441b964640a6ed78ff9e70a9214af1ca0e922e79025e4d293bc2e7e2
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
module DataMapperRest # Snagged from Active Resource, it is clean and does what needs to be done class ConnectionError < StandardError # :nodoc: attr_reader :response def initialize(response, message = nil) @response = response @message = message end def to_s "Resource action failed with code: #{response.code}, message: #{response.message if response.respond_to?(:message)}" end end # Raised when a Timeout::Error occurs. class TimeoutError < 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: # 422 class ResourceInvalid < ClientError; # :nodoc: # On this case, we could try to retrieve the validation_errors from message body: attr_reader :body def initialize(response, message = nil) super(response, message) @body = response.body unless response.body.nil? end end # 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dm-rest-adapter-0.9.11 | lib/rest_adapter/exceptions.rb |