Module: Legion::LLM::API::RoutingErrorMapper
- Extended by:
- Legion::Logging::Helper
- Includes:
- Legion::Logging::Helper
- Defined in:
- lib/legion/llm/api/routing_error_mapper.rb
Overview
SSOT v3 §18 / D16 — Maps a Phase 1 Routing::Rejection value to an immutable HTTP response triple (status, headers, body) for one of three API dialects.
Responsibilities: status, Retry-After header, and dialect-formatted body ONLY. Performs no logging inside .call, no selection, no retry, and no provider inspection.
Body shapes sourced from the existing API surface (read-only reference):
native { error: { code:, message: } }
openai { error: { message:, type:, code: } }
anthropic { type: 'error', error: { type:, message: } }
Retry-After semantics (D16): routing_too_early_retry_after setting, owned by Legion::LLM::Settings::API. Prefer SettingsState when loaded; fall back to direct bracket access on the configured path.
Defined Under Namespace
Classes: Response
Class Method Summary collapse
-
.call(rejection:, dialect:) ⇒ Response
Maps
rejectionto an immutable Response fordialect.
Class Method Details
.call(rejection:, dialect:) ⇒ Response
Maps rejection to an immutable Response for dialect.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/legion/llm/api/routing_error_mapper.rb', line 129 def self.call(rejection:, dialect:) unless DIALECTS.include?(dialect) raise ArgumentError, "[llm][routing_error_mapper] unrecognised dialect=#{dialect.inspect}; " \ "accepted: #{DIALECTS.map(&:inspect).join(', ')}" end kind = rejection.kind reason = rejection.reason.to_s status = STATUS_TABLE.fetch(kind).fetch(dialect) types = TYPE_TABLE.fetch(kind) headers = build_headers(kind: kind) body = build_body(dialect: dialect, reason: reason, types: types) Response.new(status: status, headers: headers, body: body) end |