Sha256: 4c15b090489cb200aa9183a68da78149c6ff644e5df9c347b59cf3fd9c47a1e2

Contents?: true

Size: 701 Bytes

Versions: 13

Compression:

Stored size: 701 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

    class << self
      def from_response(response)
        message = response["data"]["message"]
        error_class(response).new(message)
      end

      def error_class(response)
        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
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
billogram-0.6.5 lib/billogram/error.rb
billogram-0.6.4 lib/billogram/error.rb
billogram-0.6.3 lib/billogram/error.rb
billogram-0.6.2 lib/billogram/error.rb
billogram-0.6.1 lib/billogram/error.rb
billogram-0.6.0 lib/billogram/error.rb
billogram-0.5.6 lib/billogram/error.rb
billogram-0.5.5 lib/billogram/error.rb
billogram-0.5.4 lib/billogram/error.rb
billogram-0.5.3 lib/billogram/error.rb
billogram-0.5.2 lib/billogram/error.rb
billogram-0.5.1 lib/billogram/error.rb
billogram-0.5.0 lib/billogram/error.rb