Class: Mindee::Parsing::V2::ErrorResponse
- Inherits:
-
Object
- Object
- Mindee::Parsing::V2::ErrorResponse
- Defined in:
- lib/mindee/parsing/v2/error_response.rb
Overview
Encapsulates information returned by the API when an error occurs.
Instance Attribute Summary collapse
-
#code ⇒ String
readonly
A machine-readable code specific to the occurrence of the problem.
-
#detail ⇒ String
readonly
A human-readable explanation specific to the occurrence of the problem.
-
#errors ⇒ Array<ErrorItem>
readonly
A list of explicit error details.
-
#status ⇒ Integer
readonly
The HTTP status code returned by the server.
-
#title ⇒ String
readonly
A short, human-readable summary of the problem.
Instance Method Summary collapse
-
#as_hash ⇒ Hash
Hash representation.
-
#initialize(server_response) ⇒ ErrorResponse
constructor
A new instance of ErrorResponse.
-
#to_s ⇒ String
String representation.
Constructor Details
#initialize(server_response) ⇒ ErrorResponse
Returns a new instance of ErrorResponse.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mindee/parsing/v2/error_response.rb', line 20 def initialize(server_response) @status = server_response['status'] @detail = server_response['detail'] @title = server_response['title'] @code = server_response['code'] @errors = if server_response.key?('errors') server_response['errors'].map do |error| ErrorItem.new(error) end else [] end end |
Instance Attribute Details
#code ⇒ String (readonly)
Returns A machine-readable code specific to the occurrence of the problem.
15 16 17 |
# File 'lib/mindee/parsing/v2/error_response.rb', line 15 def code @code end |
#detail ⇒ String (readonly)
Returns A human-readable explanation specific to the occurrence of the problem.
11 12 13 |
# File 'lib/mindee/parsing/v2/error_response.rb', line 11 def detail @detail end |
#errors ⇒ Array<ErrorItem> (readonly)
Returns A list of explicit error details.
17 18 19 |
# File 'lib/mindee/parsing/v2/error_response.rb', line 17 def errors @errors end |
#status ⇒ Integer (readonly)
Returns The HTTP status code returned by the server.
9 10 11 |
# File 'lib/mindee/parsing/v2/error_response.rb', line 9 def status @status end |
#title ⇒ String (readonly)
Returns A short, human-readable summary of the problem.
13 14 15 |
# File 'lib/mindee/parsing/v2/error_response.rb', line 13 def title @title end |
Instance Method Details
#as_hash ⇒ Hash
Hash representation
42 43 44 45 46 47 |
# File 'lib/mindee/parsing/v2/error_response.rb', line 42 def as_hash { status: @status, detail: @detail, } end |
#to_s ⇒ String
String representation.
36 37 38 |
# File 'lib/mindee/parsing/v2/error_response.rb', line 36 def to_s "HTTP #{@status} - #{@title} :: #{@code} - #{@detail}" end |