Sha256: 9693986234344852645f04ce8c0626e413db0eb3959a1518510928d176c25136

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

module ShippingScale
  class Error < StandardError
    attr_reader :code, :source

    def initialize(message, code, source)
      super(message)

      @code = code
      @source = source
    end

    class << self 
      def for_code(code)
        case code 
        when "-2147219498"    ; AuthorizationError
        when "-2147219100"    ; MissingZipOriginError
        when "-2147219099"    ; MissingZipDestinationError
        when "-2147219497"    ; InvalidZipDestinationError
        when "-2147219498"    ; InvalidZipOriginError
        when "-2147219097"    ; MissingWeightError
        when "-2147219098"    ; MissingWeightError
        else                  ; Error
        end
      end
    end
  end

  class AuthorizationError < Error; end

  class ValidationError < Error; end
  class InvalidZipOriginError < ValidationError; end
  class InvalidZipDestinationError < ValidationError; end
  class MissingZipOriginError < ValidationError; end
  class MissingZipDestinationError < ValidationError; end
  class MissingWeightError < ValidationError; end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shipping-scale-0.1.2 lib/shipping_scale/error.rb
shipping-scale-0.1.0 lib/shipping_scale/error.rb