Exception: PBShipping::ApiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/pbshipping/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, http_code = nil, http_body = nil) ⇒ ApiError



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pbshipping/error.rb', line 22

def initialize(message, http_code=nil, http_body=nil)
  @message = message
  @http_code = http_code
  @http_body = http_body
  @error_info = []
  if http_body != nil 
    begin 
      json_error = PBShipping::json_parse(http_body)
    rescue => e
    end
    if json_error.is_a?(Array)
      for next_err in json_error
        if next_err.key?(:key) == true 
          @error_info << {
            :errorCode => next_err[:key], 
            :message => next_err[:message]
          }
        elsif next_err.key?(:errorCode) == true
          @error_info << {
            :errorCode => next_err[:errorCode], 
            :message => next_err[:message]
          }
        end
      end
    elsif json_error.is_a?(Hash) && json_error.key?(:errors)
      for next_err in json_error[:errors]
        @error_info << {
          :errorCode => next_err[:errorCode],
          :message => next_err[:errorDescription]
        }
      end
    end
  end
end

Instance Attribute Details

#error_infoObject (readonly)

Returns the value of attribute error_info.



21
22
23
# File 'lib/pbshipping/error.rb', line 21

def error_info
  @error_info
end

#http_bodyObject (readonly)

Returns the value of attribute http_body.



21
22
23
# File 'lib/pbshipping/error.rb', line 21

def http_body
  @http_body
end

#http_codeObject (readonly)

Returns the value of attribute http_code.



21
22
23
# File 'lib/pbshipping/error.rb', line 21

def http_code
  @http_code
end

#messageObject (readonly)

Returns the value of attribute message.



21
22
23
# File 'lib/pbshipping/error.rb', line 21

def message
  @message
end

Instance Method Details

#to_sObject



57
58
59
60
61
62
63
64
# File 'lib/pbshipping/error.rb', line 57

def to_s
  if http_body != nil
    msg = @message + " " + http_body.to_s
  else
    msg = @message
  end
  return msg
end