Sha256: 9eb64b7b4703a2f384dc964e869e7fc8b8d6f1326966bbcf0151bee93fccf5cb

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

module PagarMe
  class PagarMeError < StandardError
  end

  class ConnectionError < PagarMeError
    attr_reader :error

    def initialize(error)
      @error = error
      super error.message
    end
  end

  class RequestError < PagarMeError
  end

  class ResponseError < PagarMeError
    attr_reader :request_params, :error

    def initialize(request_params, error)
      @request_params, @error = request_params, error
      super @error.message
    end
  end

  class NotFound < ResponseError
    attr_reader :response
    def initialize(response, request_params, error)
      @response = response
      super request_params, error
    end
  end

  class ValidationError < PagarMeError
    attr_reader :response, :errors

    def initialize(response)
      @response = response
      @errors   = response['errors'].map do |error|
        params = error.values_at('message', 'parameter_name', 'type', 'url')
        ParamError.new(*params)
      end
      super @errors.map(&:message).join(', ')
    end

    def to_h
      @errors.map(&:to_h)
    end
  end

  class ParamError < PagarMeError
    attr_reader :parameter_name, :type, :url

    def initialize(message, parameter_name, type, url)
      @parameter_name, @type, @url = parameter_name, type, url
      super message
    end

    def to_h
      { parameter_name: parameter_name , type: type , message: message }
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pagarme-2.4.0 lib/pagarme/errors.rb
pagarme-2.3.0 lib/pagarme/errors.rb
pagarme-2.2.3 lib/pagarme/errors.rb
pagarme-2.2.2 lib/pagarme/errors.rb
pagarme-2.2.1 lib/pagarme/errors.rb
pagarme-2.2.0 lib/pagarme/errors.rb
pagarme-2.1.4 lib/pagarme/errors.rb