class ObjectFramework::HTTP::ProblemPresenter
Presents registered safe errors as RFC 9457 problem details, including the ExecutionContext operation ID. Exception messages are not exposed.
Constants
- STATUSES
Public Class Methods
Source
# File lib/object_framework/http/presentation.rb, line 53 def self.fallback(context:) body = '{"type":"urn:object-framework:error:internal_error","title":"Internal server error","status":500,"code":"internal_error","operation_id":"' + context.operation_id + '","instance":"urn:uuid:' + context.operation_id + '"}' Response.new(status: 500, headers: { "Content-Type" => "application/problem+json" }, body:) end
Source
# File lib/object_framework/http/presentation.rb, line 36 def initialize(registry:) @registry = registry end
Public Instance Methods
Source
# File lib/object_framework/http/presentation.rb, line 40 def call(exception, context:) description = @registry.resolve(exception) status = exception.is_a?(Error) ? exception.class::STATUS : STATUSES.fetch(description.category) problem = description.details.transform_keys(&:to_s).merge( "type" => "urn:object-framework:error:#{description.code}", "title" => description.title, "status" => status, "instance" => "urn:uuid:#{context.operation_id}", "code" => description.code, "operation_id" => context.operation_id ) headers = { "Content-Type" => "application/problem+json" } headers.merge!(exception.headers) if exception.is_a?(Error) Response.new(status:, headers:, body: JSON.generate(problem)) end