Class: GeminiApi::FailureResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/gemini_api/failure_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ FailureResponse

Returns a new instance of FailureResponse.



5
6
7
# File 'lib/gemini_api/failure_response.rb', line 5

def initialize(response)
  @response = response
end

Instance Method Details

#bodyObject



31
32
33
# File 'lib/gemini_api/failure_response.rb', line 31

def body
  response.body
end

#errorObject



23
24
25
# File 'lib/gemini_api/failure_response.rb', line 23

def error
  errors.first
end

#errorsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gemini_api/failure_response.rb', line 9

def errors
  if json?
    parsed_response = response.parse
    [
      PartnerApi::Errors::RequestError.new(
        code: parsed_response['reason'],
        message: parsed_response['message']
      )
    ]
  else
    [PartnerApi::Errors::RequestError.new(message: "Invalid Response: #{body}")]
  end
end

#headersObject



35
36
37
# File 'lib/gemini_api/failure_response.rb', line 35

def headers
  response.headers.to_h
end

#statusObject



27
28
29
# File 'lib/gemini_api/failure_response.rb', line 27

def status
  response.status
end