Exception: LittleGhost::Providers::OpenAICompatible::StreamError
- Inherits:
-
LittleGhost::ProviderError
- Object
- StandardError
- Error
- LittleGhost::ProviderError
- LittleGhost::Providers::OpenAICompatible::StreamError
- Defined in:
- lib/little_ghost/providers/openai_compatible.rb
Overview
Represents a structured error received inside an otherwise successful provider stream.
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Normalized provider error type and optional provider code.
-
#error_type ⇒ Object
readonly
Normalized provider error type and optional provider code.
Class Method Summary collapse
-
.from(error, prefix:) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(message, error_type: nil, code: nil) ⇒ StreamError
constructor
Creates a structured stream error.
-
#retryable? ⇒ Boolean
Indicates whether LittleGhost may retry this provider error.
Constructor Details
#initialize(message, error_type: nil, code: nil) ⇒ StreamError
Creates a structured stream error.
48 49 50 51 52 |
# File 'lib/little_ghost/providers/openai_compatible.rb', line 48 def initialize(, error_type: nil, code: nil) @error_type = error_type.to_s.strip.downcase @code = code super() end |
Instance Attribute Details
#code ⇒ Object (readonly)
Normalized provider error type and optional provider code.
45 46 47 |
# File 'lib/little_ghost/providers/openai_compatible.rb', line 45 def code @code end |
#error_type ⇒ Object (readonly)
Normalized provider error type and optional provider code.
45 46 47 |
# File 'lib/little_ghost/providers/openai_compatible.rb', line 45 def error_type @error_type end |
Class Method Details
.from(error, prefix:) ⇒ Object
:nodoc:
63 64 65 66 67 68 69 70 71 |
# File 'lib/little_ghost/providers/openai_compatible.rb', line 63 def self.from(error, prefix:) # :nodoc: value = error.is_a?(Hash) ? error : {} = value["metadata"].is_a?(Hash) ? value["metadata"] : {} error_type = ["error_type"] || value["type"] code = value["code"] = value["message"].to_s = "unknown error" if .empty? new("#{prefix}: #{}", error_type:, code:) end |
Instance Method Details
#retryable? ⇒ Boolean
Indicates whether LittleGhost may retry this provider error.
55 56 57 58 59 60 61 |
# File 'lib/little_ghost/providers/openai_compatible.rb', line 55 def retryable? return true if TRANSIENT_STREAM_ERROR_TYPES.include?(error_type) return true if code.to_s.strip.downcase == "server_error" status = Integer(code, exception: false) status == 408 || status == 429 || (status && status >= 500) end |