Module: Ollama::Errors
- Defined in:
- lib/ollama/errors.rb
Overview
Maps HTTP-style responses into typed runtime errors.
Class Method Summary collapse
Class Method Details
.from_response(response, requested_model: nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ollama/errors.rb', line 33 def self.from_response(response, requested_model: nil) status = response.code.to_i = begin parsed = JSON.parse(response.body.to_s) parsed.is_a?(Hash) ? (parsed["error"] || parsed["message"] || response.) : response. rescue JSON::ParserError response. end case status when 401 UnauthorizedError.new("HTTP 401: #{}", 401) when 404 NotFoundError.new(, requested_model: requested_model) when 429 RateLimitError.new("HTTP 429: #{}", 429) when 503 ModelUnavailableError.new("HTTP 503: #{}", 503) else HTTPError.new("HTTP #{status}: #{}", status) end end |