Module: RubyLLM::Providers::OpenAI::Streaming
- Defined in:
- lib/pikuri/ruby_llm_patches.rb
Class Method Summary collapse
-
.parse_streaming_error(data) ⇒ Array(Integer, nil), String
Parse a streaming error body into a
[status, message]pair, tolerating a non-Hash parsed body.
Class Method Details
.parse_streaming_error(data) ⇒ Array(Integer, nil), String
Parse a streaming error body into a [status, message] pair,
tolerating a non-Hash parsed body. See
Pikuri::RubyLlmPatches for why this override exists and when
to remove it (ruby_llm #837).
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/pikuri/ruby_llm_patches.rb', line 81 def parse_streaming_error(data) error_data = JSON.parse(data) # Non-Hash body (a bare JSON string/number/array): no structured # error to read — surface it as the message, defer status. return [nil, error_data.to_s] unless error_data.is_a?(Hash) error = error_data['error'] return [nil, error_data.to_s] unless error # A string error value (xAI/Grok's {"error": "..."}) has no type # field — hand it up as-is, defer status to the HTTP response. return [nil, error] if error.is_a?(String) case error['type'] when 'server_error' [500, error['message']] when 'rate_limit_exceeded', 'insufficient_quota' [429, error['message']] else [400, error['message']] end end |