class RailsAiAdmin::Presentation::Status
Fixed public status text. Exceptions, params and record values are not inputs.
Constants
- DEFINITIONS
Public Class Methods
Source
# File lib/rails_ai_admin/presentation/status.rb, line 18 def self.fetch(kind) raise ConfigurationError, "Unknown status kind" unless kind.is_a?(String) || kind.is_a?(Symbol) key = kind.to_s http_status, code, title, message = DEFINITIONS.fetch(key) { raise ConfigurationError, "Unknown status kind" } # The English text is the fallback, so a missing translation never # breaks the page that reports another failure. title = I18n.t(:title, scope: [ :rails_ai_admin, :statuses, key ], default: title).to_s.freeze message = I18n.t(:message, scope: [ :rails_ai_admin, :statuses, key ], default: message).to_s.freeze new(String.new(key).freeze, http_status, code, title, message) end
Source
# File lib/rails_ai_admin/presentation/status.rb, line 29 def self.for_code(code) kind = case code when "UNAUTHENTICATED" then :authentication_required when "INVALID_QUERY" then :invalid_query when "CONFLICT", "SELECTION_EXPIRED", "SELECTION_INVALIDATED" then :conflict else :not_found end fetch(kind) end