Exception: RubyLLM::Error
- Inherits:
-
StandardError
- Object
- StandardError
- RubyLLM::Error
- Defined in:
- lib/ruby_llm/error.rb
Overview
Error is the base class for provider-operation errors raised by RubyLLM, including API, network, capability, and provider response-shape failures. When an HTTP response is available, it wraps that response and normalizes the message across providers. Subclasses map common HTTP status codes: BadRequestError (400), UnauthorizedError (401), PaymentRequiredError (402), ForbiddenError (403), RateLimitError (429), ServerError (500), ServiceUnavailableError (502 to 504), and OverloadedError (529).
begin
RubyLLM.chat.ask "Translate 'hello' to French."
rescue RubyLLM::RateLimitError
puts "Rate limit hit. Please wait a moment."
rescue RubyLLM::Error => e
puts "API error: #{e.}"
puts e.response&.status
end
Local setup and programming errors, such as ConfigurationError and ModelNotFoundError, inherit from StandardError directly and are not caught by rescuing Error.
Direct Known Subclasses
BadRequestError, ContextLengthExceededError, ForbiddenError, OverloadedError, PaymentRequiredError, RateLimitError, ResearchJob::Error, ServerError, ServiceUnavailableError, ToolCallParseError, UnauthorizedError, UnsupportedAttachmentError, UnsupportedServerToolError
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
The HTTP response that caused the error, or
nilwhen none is available.
Class Method Summary collapse
-
.default_message ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(message = nil, response: nil) ⇒ Error
constructor
Creates an error with
message.
Constructor Details
#initialize(message = nil, response: nil) ⇒ Error
Creates an error with message. Pass response: to attach the HTTP
response; its body supplies the message when message is nil.
36 37 38 39 |
# File 'lib/ruby_llm/error.rb', line 36 def initialize( = nil, response: nil) @response = response super( || response&.body || self.class.) end |
Instance Attribute Details
#response ⇒ Object (readonly)
The HTTP response that caused the error, or nil when none is
available. Its status and body carry the provider's reply.
28 29 30 |
# File 'lib/ruby_llm/error.rb', line 28 def response @response end |
Class Method Details
.default_message ⇒ Object
:nodoc:
30 31 32 |
# File 'lib/ruby_llm/error.rb', line 30 def self. # :nodoc: nil end |