Module: Railsmith::ControllerHelpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/railsmith/controller_helpers.rb
Overview
Include this concern in an ApplicationController (or a specific controller) to get automatic JSON error responses when a service raises Failure.
Constant Summary collapse
- ERROR_STATUS_MAP =
Maps Railsmith error codes to HTTP status symbols understood by Rails’ render json:, status:.
{ "validation_error" => :unprocessable_entity, "not_found" => :not_found, "conflict" => :conflict, "unauthorized" => :unauthorized, "unexpected" => :internal_server_error }.freeze
Instance Method Summary collapse
-
#railsmith_context(domain: nil, **extras) ⇒ Railsmith::Context
Builds a Context seeded with the incoming request’s id, so every service invoked from this controller shares the same
request_idas theX-Request-Idheader ActionDispatch observed.
Instance Method Details
#railsmith_context(domain: nil, **extras) ⇒ Railsmith::Context
Builds a Railsmith::Context seeded with the incoming request’s id, so every service invoked from this controller shares the same request_id as the X-Request-Id header ActionDispatch observed.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/railsmith/controller_helpers.rb', line 65 def railsmith_context(domain: nil, **extras) request_id = extras.delete(:request_id) request_id ||= request.request_id if respond_to?(:request) && request.respond_to?(:request_id) Railsmith::Context.new( domain: domain, request_id: request_id, **extras ) end |