Sha256: e03fe0468acd4253be5ca644654105ac782790ee16b714fa740e87fec6ff7912

Contents?: true

Size: 705 Bytes

Versions: 2

Compression:

Stored size: 705 Bytes

Contents

module Billogram
  class Error < StandardError

    class BadRequest < Error; end
    class Unauthorized < Error; end
    class Forbidden < Error; end
    class NotFound < Error; end
    class InternalServerError < Error; end

    def self.from_response(response)
      if klass =  case response.code.to_i
                  when 400      then BadRequest
                  when 401      then Unauthorized
                  when 403      then Forbidden
                  when 404      then NotFound
                  when 500      then InternalServerError
                  else               Billogram::Error
                  end
        klass.new(response["data"]["message"])
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
billogram-0.4.2 lib/billogram/error.rb
billogram-0.4.1 lib/billogram/error.rb