Module: Mistri::ErrorData

Defined in:
lib/mistri/errors.rb

Overview

The machine-readable shape of a stream failure, carried on errored assistant messages so retry policies and hosts can classify without parsing prose. Strings are the assemblers' synthesized truncation reasons.

Class Method Summary collapse

Class Method Details

.for(reason) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mistri/errors.rb', line 82

def for(reason)
  case reason
  when RateLimitError
    { "type" => "RateLimitError", "status" => reason.status,
      "retry_after" => reason.retry_after }.compact
  when ProviderError
    { "type" => reason.class.name.split("::").last, "status" => reason.status }.compact
  when Exception then { "type" => reason.class.name }
  else { "type" => "TruncatedStream" }
  end
end