Sha256: 7e5315345738e08f7ac5b6e2d5672ddf5734a8ae4dc7c335f4178f21bfd13191

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

module Buckaruby
  # Base class for exceptions.
  class BuckarooException < StandardError
  end

  # Exception raised when an API call to Buckaroo results in a "Fail".
  class ApiException < BuckarooException
    attr_reader :params

    def initialize(params = {})
      @params = params

      if status_message && status_code
        message = "API request failed: #{status_message} (#{status_code})"
      elsif error_message
        message = "API request failed: #{error_message}"
      else
        message = "API request failed"
      end

      super(message)
    end

    def status_message
      params[:brq_statusmessage]
    end

    def status_code
      params[:brq_statuscode]
    end

    def error_message
      params[:brq_apierrormessage]
    end
  end

  # Exception raised when a request to Buckaroo fails because of connection problems.
  class ConnectionException < BuckarooException
    def initialize(exception)
      message = "Error connecting to Buckaroo: #{exception.message} (#{exception.class})"

      super(message)
    end
  end

  # Exception raised when the signature could not be verified.
  class SignatureException < BuckarooException
    def initialize(sent_signature = "", generated_signature = "")
      message = "Sent signature (#{sent_signature}) doesn't match generated signature (#{generated_signature})"

      super(message)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
buckaruby-1.0.1 lib/buckaruby/exception.rb
buckaruby-1.0.0 lib/buckaruby/exception.rb