Exception: ImmersiveCommons::ApiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/immersivecommons/client.rb

Overview

Raised on a non-2xx response. Carries the parsed error body + metadata.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, operation_id, body) ⇒ ApiError

Returns a new instance of ApiError.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/immersivecommons/client.rb', line 21

def initialize(status, operation_id, body)
  @status = status
  @operation_id = operation_id
  @body = body.is_a?(Hash) ? body : {}
  @error_kind = @body["error_kind"].is_a?(String) ? @body["error_kind"] : nil
  ra = @body["retry_after_seconds"]
  @retry_after_seconds = ra.is_a?(Integer) ? ra : nil

  err = @body["error"]
  msg = if err.is_a?(String)
          err
        elsif err.is_a?(Hash)
          [err["code"], err["message"]].compact.join(": ")
        end
  msg = @body["message"] if (msg.nil? || msg.empty?) && @body["message"].is_a?(String)
  text = "#{operation_id} failed (HTTP #{status})"
  text += ": #{msg}" if msg && !msg.empty?
  super(text)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



19
20
21
# File 'lib/immersivecommons/client.rb', line 19

def body
  @body
end

#error_kindObject (readonly)

Returns the value of attribute error_kind.



19
20
21
# File 'lib/immersivecommons/client.rb', line 19

def error_kind
  @error_kind
end

#operation_idObject (readonly)

Returns the value of attribute operation_id.



19
20
21
# File 'lib/immersivecommons/client.rb', line 19

def operation_id
  @operation_id
end

#retry_after_secondsObject (readonly)

Returns the value of attribute retry_after_seconds.



19
20
21
# File 'lib/immersivecommons/client.rb', line 19

def retry_after_seconds
  @retry_after_seconds
end

#statusObject (readonly)

Returns the value of attribute status.



19
20
21
# File 'lib/immersivecommons/client.rb', line 19

def status
  @status
end