Class: Mindee::Parsing::V2::ErrorResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/parsing/v2/error_response.rb

Overview

Encapsulates information returned by the API when an error occurs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_response) ⇒ ErrorResponse

Returns a new instance of ErrorResponse.

Parameters:

  • server_response (Hash)

    Raw JSON parsed into a Hash.



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

#codeString (readonly)

Returns A machine-readable code specific to the occurrence of the problem.

Returns:

  • (String)

    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

#detailString (readonly)

Returns A human-readable explanation specific to the occurrence of the problem.

Returns:

  • (String)

    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

#errorsArray<ErrorItem> (readonly)

Returns A list of explicit error details.

Returns:

  • (Array<ErrorItem>)

    A list of explicit error details.



17
18
19
# File 'lib/mindee/parsing/v2/error_response.rb', line 17

def errors
  @errors
end

#statusInteger (readonly)

Returns The HTTP status code returned by the server.

Returns:

  • (Integer)

    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

#titleString (readonly)

Returns A short, human-readable summary of the problem.

Returns:

  • (String)

    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_hashHash

Hash representation

Returns:

  • (Hash)

    Hash representation of the object.



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_sString

String representation.

Returns:

  • (String)


36
37
38
# File 'lib/mindee/parsing/v2/error_response.rb', line 36

def to_s
  "HTTP #{@status} - #{@title} :: #{@code} - #{@detail}"
end