Class: LLM::OpenAI::ErrorHandler
- Inherits:
-
Object
- Object
- LLM::OpenAI::ErrorHandler
- Defined in:
- lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/error_handler.rb
Instance Attribute Summary collapse
-
#res ⇒ Net::HTTPResponse
readonly
Non-2XX response from the server.
Instance Method Summary collapse
Constructor Details
#initialize(res) ⇒ LLM::OpenAI::ErrorHandler
16 17 18 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/error_handler.rb', line 16 def initialize(res) @res = res end |
Instance Attribute Details
#res ⇒ Net::HTTPResponse (readonly)
Returns Non-2XX response from the server.
10 11 12 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/error_handler.rb', line 10 def res @res end |
Instance Method Details
#raise_error! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/openai/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 error = body["error"] || {} case error["type"] when "server_error" then raise LLM::ServerError.new { _1.response = res }, error["message"] else raise LLM::ResponseError.new { _1.response = res }, error["message"] || "Unexpected response" end end end |