Sha256: 97b14e1b4df2f9e4057f472f8ad4a10fd99ab74ac86a448e380970eb914d13a5

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# Copyright (c) 2011, uEncode, Cássio Marques

module UEncode
  class Response
    class BadRequestError    < StandardError; end
    class NotAuthorizedError < StandardError; end
    class BadRequesError     < StandardError; end
    class UnacceptableError  < StandardError; end
    class NotFoundError      < StandardError; end
    class ServerError        < StandardError; end
    class UnknownError       < StandardError; end

    ATTRIBUTES = [:code, :data]

    include AttrSetting    

    def initialize(options)
      check_response_code options[:code], options[:data]
      super
    end

    private
    def check_response_code(code, data)
      return if code == 200
      case code
      when 401; raise NotAuthorizedError, data
      when 403; raise NotAuthorizedError, data
      when 400; raise BadRequestError, data
      when 406; raise UnacceptableError, data
      when 404; raise NotFoundError, data
      when 500; raise ServerError, message
      else raise UnknownError, "#{code} : #{data}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uencode-3.1.0 lib/uencode/response.rb