Class: LLM::Ollama::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/error_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(res) ⇒ LLM::OpenAI::ErrorHandler

Parameters:

  • res (Net::HTTPResponse)

    The response from the server



16
17
18
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/error_handler.rb', line 16

def initialize(res)
  @res = res
end

Instance Attribute Details

#resNet::HTTPResponse (readonly)

Returns Non-2XX response from the server.

Returns:

  • (Net::HTTPResponse)

    Non-2XX response from the server



10
11
12
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/error_handler.rb', line 10

def res
  @res
end

Instance Method Details

#raise_error!Object

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/ollama/error_handler.rb', line 23

def raise_error!
  case res
  when Net::HTTPServerError
    raise LLM::ServerError.new { _1.response = res }, "Server error"
  when Net::HTTPUnauthorized
    raise LLM::UnauthorizedError.new { _1.response = res }, "Authentication error"
  when Net::HTTPTooManyRequests
    raise LLM::RateLimitError.new { _1.response = res }, "Too many requests"
  else
    raise LLM::ResponseError.new { _1.response = res }, "Unexpected response"
  end
end