Exception: EasyPost::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, http_status = nil, http_body = nil, json_body = {}) ⇒ Error

Returns a new instance of Error.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/easypost/error.rb', line 11

def initialize(message=nil, http_status=nil, http_body=nil, json_body={})
  @message = message
  @http_status = http_status
  @http_body = http_body
  @json_body = json_body

  @param = @json_body.fetch(:error, {}).fetch(:param, nil)
  @code = @json_body.fetch(:error, {}).fetch(:code, nil)
  @errors = @json_body.fetch(:error, {}).fetch(:errors, nil)

  super(message)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/easypost/error.rb', line 8

def code
  @code
end

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/easypost/error.rb', line 9

def errors
  @errors
end

#http_bodyObject (readonly)

Returns the value of attribute http_body.



5
6
7
# File 'lib/easypost/error.rb', line 5

def http_body
  @http_body
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



4
5
6
# File 'lib/easypost/error.rb', line 4

def http_status
  @http_status
end

#json_bodyObject (readonly)

Returns the value of attribute json_body.



6
7
8
# File 'lib/easypost/error.rb', line 6

def json_body
  @json_body
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/easypost/error.rb', line 3

def message
  @message
end

#paramObject (readonly)

Returns the value of attribute param.



7
8
9
# File 'lib/easypost/error.rb', line 7

def param
  @param
end

Instance Method Details

#to_sObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/easypost/error.rb', line 24

def to_s
  s = "#{@code} (#{@http_status}): #{@message}";
  if @errors
      s += "\nField errors:\n"
      @errors.each do |field_error|
        field_error.each do |k, v|
          s += "  #{k}: #{v}\n"
        end
        s += "\n"
      end
  end
  s
end