Sha256: f2a98d5389eed111ffddd1422d43ab5b702134265011752ae363bc5c46791cc1

Contents?: true

Size: 825 Bytes

Versions: 7

Compression:

Stored size: 825 Bytes

Contents

module Ribose
  class Error < StandardError
    def initialize(response = nil)
      @response = response
      super
    end

    def self.from_response(response)
      status = response[:status].to_i
      if klass = case status
                 when 400 then Ribose::BadRequest
                 when 401 then Ribose::Unauthorized
                 when 403 then Ribose::Forbidden
                 when 404 then Ribose::NotFound
                 when 422 then Ribose::UnprocessableEntity
                 when 500..599 then Ribose::ServerError
                 end

        klass.new(response)
      end
    end
  end

  class BadRequest < Error; end
  class Unauthorized < Error; end
  class Forbidden < Error; end
  class NotFound < Error; end
  class UnprocessableEntity < Error; end
  class ServerError < Error; end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ribose-0.5.0 lib/ribose/error.rb
ribose-0.4.1 lib/ribose/error.rb
ribose-0.4.0 lib/ribose/error.rb
ribose-0.3.2 lib/ribose/error.rb
ribose-0.3.1 lib/ribose/error.rb
ribose-0.3.0 lib/ribose/error.rb
ribose-0.2.0 lib/ribose/error.rb