Class: Geminize::ErrorParser

Inherits:
Object
  • Object
show all
Defined in:
lib/geminize/error_parser.rb

Overview

Utility class for parsing error responses from the Gemini API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ErrorParser

Initialize a new parser

Parameters:

  • response (Faraday::Response)

    The response object



20
21
22
# File 'lib/geminize/error_parser.rb', line 20

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseFaraday::Response (readonly)

Returns The response object.

Returns:

  • (Faraday::Response)

    The response object



16
17
18
# File 'lib/geminize/error_parser.rb', line 16

def response
  @response
end

Class Method Details

.parse(response) ⇒ Hash

Parse an error response and extract relevant information

Parameters:

  • response (Faraday::Response)

    The response object

Returns:

  • (Hash)

    Hash containing extracted error information



11
12
13
# File 'lib/geminize/error_parser.rb', line 11

def self.parse(response)
  new(response).parse
end

Instance Method Details

#parseHash

Parse the response and extract error information

Returns:

  • (Hash)

    Hash containing error code, message, and status



26
27
28
29
30
31
32
# File 'lib/geminize/error_parser.rb', line 26

def parse
  {
    http_status: response.status,
    code: extract_error_code,
    message: extract_error_message
  }
end