Sha256: 44280a8788d2b75291424a9040fe37882bcfeeee8e493203b6387cf2c6209fed
Contents?: true
Size: 1.29 KB
Versions: 30
Compression:
Stored size: 1.29 KB
Contents
class Ey::Core::Response class Error < StandardError attr_reader :response def initialize(response) @response = response super( { :status => response.status, :headers => response.headers, :body => response.body, :request => response.request }.inspect ) end def error_type self.class.name.split(":").last end end BadRequest = Class.new(Error) Conflict = Class.new(Error) NotFound = Class.new(Error) RateLimitExceeded = Class.new(Error) Unauthorized = Class.new(Error) Unexpected = Class.new(Error) Unprocessable = Class.new(Error) EXCEPTION_MAPPING = { 400 => BadRequest, 401 => Unauthorized, 404 => NotFound, 409 => Conflict, 422 => Unprocessable, 429 => RateLimitExceeded, 500 => Unexpected, } attr_reader :headers, :status, :body, :request def initialize(opts = {}) @status = opts[:status] @headers = opts[:headers] @body = opts[:body] @request = opts[:request] end def successful? self.status >= 200 && self.status <= 299 || self.status == 304 end def raise! if !successful? raise (EXCEPTION_MAPPING[self.status] || Error).new(self) else self end end end
Version data entries
30 entries across 30 versions & 2 rubygems