Class: SkillBench::Clients::ResponseErrorHandler
- Inherits:
-
Object
- Object
- SkillBench::Clients::ResponseErrorHandler
- Defined in:
- lib/skill_bench/clients/response_error_handler.rb
Overview
Handles error responses and logging for LLM provider clients. Encapsulates error formatting, logging, and exception handling.
Constant Summary collapse
- API_FAILED =
'API Request failed'
Class Method Summary collapse
-
.failure_response(response, parsed, &usage_extractor) ⇒ Hash
Creates an error response for failed HTTP requests.
-
.handle_exception(error, type) ⇒ Hash
Handles an exception by logging and returning a standardized error response.
-
.log_error(error) ⇒ void
Logs an error message and backtrace to Rails.logger or stderr.
-
.missing_message_response(response, parsed, &usage_extractor) ⇒ Hash
Creates an error response when the LLM response has no message content.
Class Method Details
.failure_response(response, parsed, &usage_extractor) ⇒ Hash
Creates an error response for failed HTTP requests.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/skill_bench/clients/response_error_handler.rb', line 16 def self.failure_response(response, parsed, &usage_extractor) error_msg = "#{API_FAILED}: #{response.status}" detail = parsed.is_a?(Hash) ? (parsed[:error] || parsed['error'] || parsed) : parsed if detail.is_a?(Hash) && (detail[:message] || detail['message']) error_msg += " - #{detail[:message] || detail['message']}" elsif !detail.to_s.empty? error_msg += " - #{detail}" end base_response = ResponseBuilder.api_error(error_message: error_msg, usage: usage_extractor.call(parsed)) base_response.merge(code: response.status) end |
.handle_exception(error, type) ⇒ Hash
Handles an exception by logging and returning a standardized error response.
47 48 49 50 |
# File 'lib/skill_bench/clients/response_error_handler.rb', line 47 def self.handle_exception(error, type) log_error(error) ResponseBuilder.error(message: "#{type}: #{error.}") end |
.log_error(error) ⇒ void
This method returns an undefined value.
Logs an error message and backtrace to Rails.logger or stderr.
56 57 58 |
# File 'lib/skill_bench/clients/response_error_handler.rb', line 56 def self.log_error(error) SkillBench::ErrorLogger.log_error(error) end |
.missing_message_response(response, parsed, &usage_extractor) ⇒ Hash
Creates an error response when the LLM response has no message content.
36 37 38 39 40 |
# File 'lib/skill_bench/clients/response_error_handler.rb', line 36 def self.(response, parsed, &usage_extractor) error_msg = 'LLM response missing message content' base_response = ResponseBuilder.error(message: error_msg) base_response.merge(usage: usage_extractor.call(parsed), code: response.status) end |