Exception: PBShipping::ApiError
- Inherits:
-
StandardError
- Object
- StandardError
- PBShipping::ApiError
- Defined in:
- lib/pbshipping/error.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#error_info ⇒ Object
readonly
Returns the value of attribute error_info.
-
#http_body ⇒ Object
readonly
Returns the value of attribute http_body.
-
#http_code ⇒ Object
readonly
Returns the value of attribute http_code.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(message, http_code = nil, http_body = nil) ⇒ ApiError
constructor
A new instance of ApiError.
- #to_s ⇒ Object
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(, http_code=nil, http_body=nil) = @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_info ⇒ Object (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_body ⇒ Object (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_code ⇒ Object (readonly)
Returns the value of attribute http_code.
21 22 23 |
# File 'lib/pbshipping/error.rb', line 21 def http_code @http_code end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
21 22 23 |
# File 'lib/pbshipping/error.rb', line 21 def end |
Instance Method Details
#to_s ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/pbshipping/error.rb', line 57 def to_s if http_body != nil msg = + " " + http_body.to_s else msg = end return msg end |