Exception: LittleGhost::Providers::OpenAICompatible::StreamError

Inherits:
LittleGhost::ProviderError show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, error_type: nil, code: nil) ⇒ StreamError

Creates a structured stream error.



53
54
55
56
57
# File 'lib/little_ghost/providers/openai_compatible.rb', line 53

def initialize(message, error_type: nil, code: nil)
  @error_type = error_type.to_s.strip.downcase
  @code = code
  super(message)
end

Instance Attribute Details

#codeObject (readonly)

Normalized provider error type and optional provider code.



50
51
52
# File 'lib/little_ghost/providers/openai_compatible.rb', line 50

def code
  @code
end

#error_typeObject (readonly)

Normalized provider error type and optional provider code.



50
51
52
# File 'lib/little_ghost/providers/openai_compatible.rb', line 50

def error_type
  @error_type
end

Class Method Details

.from(error, prefix:) ⇒ Object

:nodoc:



68
69
70
71
72
73
74
75
76
# File 'lib/little_ghost/providers/openai_compatible.rb', line 68

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"]
  message = value["message"].to_s
  message = "unknown error" if message.empty?
  new("#{prefix}: #{message}", error_type:, code:)
end

Instance Method Details

#retryable?Boolean

Indicates whether LittleGhost may retry this provider error.

Returns:

  • (Boolean)


60
61
62
63
64
65
66
# File 'lib/little_ghost/providers/openai_compatible.rb', line 60

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