Module: Ollama::HttpErrorHandler
- Defined in:
- lib/ollama/http_error_handler.rb
Overview
Shared HTTP error handling for all API clients
Instance Method Summary collapse
-
#extract_error_message(response) ⇒ String?
Extract error message from response body.
-
#handle_http_error(response, requested_model: nil) ⇒ Object
Handle HTTP error response and raise appropriate Ollama error.
Instance Method Details
#extract_error_message(response) ⇒ String?
Extract error message from response body
32 33 34 35 36 37 38 39 40 |
# File 'lib/ollama/http_error_handler.rb', line 32 def (response) body = response.body return nil if body.nil? || body.empty? parsed = JSON.parse(body) parsed["error"] if parsed.is_a?(Hash) rescue JSON::ParserError nil end |
#handle_http_error(response, requested_model: nil) ⇒ Object
Handle HTTP error response and raise appropriate Ollama error
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ollama/http_error_handler.rb', line 13 def handle_http_error(response, requested_model: nil) status_code = response.code.to_i = (response) || response. case status_code when 401 raise UnauthorizedError.new("HTTP 401: #{}", 401) when 404 raise NotFoundError.new(, requested_model: requested_model) when 503 raise ModelUnavailableError.new("HTTP 503: #{}", 503) else raise HTTPError.new("HTTP #{status_code}: #{}", status_code) end end |