Exception: ImmersiveCommons::ApiError
- Inherits:
-
StandardError
- Object
- StandardError
- ImmersiveCommons::ApiError
- Defined in:
- lib/immersivecommons/client.rb
Overview
Raised on a non-2xx response. Carries the parsed error body + metadata.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#error_kind ⇒ Object
readonly
Returns the value of attribute error_kind.
-
#operation_id ⇒ Object
readonly
Returns the value of attribute operation_id.
-
#retry_after_seconds ⇒ Object
readonly
Returns the value of attribute retry_after_seconds.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(status, operation_id, body) ⇒ ApiError
constructor
A new instance of ApiError.
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
19 20 21 |
# File 'lib/immersivecommons/client.rb', line 19 def body @body end |
#error_kind ⇒ Object (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_id ⇒ Object (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_seconds ⇒ Object (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 |
#status ⇒ Object (readonly)
Returns the value of attribute status.
19 20 21 |
# File 'lib/immersivecommons/client.rb', line 19 def status @status end |