class Noise::ExceptionResponder
Constructs error response (status, body)
Attributes
env[R]
exception_renderer[R]
Public Class Methods
new(env, exception_renderer = Noise.config.exception_renderer.new(env))
click to toggle source
@param env [Hash] rack env @param exception_renderer
[ExceptionRenderer]
# File lib/noise/exception_responder.rb, line 24 def initialize(env, exception_renderer = Noise.config.exception_renderer.new(env)) @env = env @exception_renderer = exception_renderer end
register(error, status:)
click to toggle source
@param error [StandardError] @param status [Integer, Symbol] HTTP status to use for response @api private
# File lib/noise/exception_responder.rb, line 17 def register(error, status:) ActionDispatch::ExceptionWrapper.rescue_responses[error.to_s] = status end
Public Instance Methods
body()
click to toggle source
@return [Hash] JSON-serializable body
# File lib/noise/exception_responder.rb, line 33 def body @body ||= exception_renderer.render(self) end
error()
click to toggle source
# File lib/noise/exception_responder.rb, line 52 def error env['action_dispatch.exception'] end
headers()
click to toggle source
@return [Hash] headers
# File lib/noise/exception_responder.rb, line 38 def headers { 'Content-Type' => "#{::Mime[:json]}; charset=#{ActionDispatch::Response.default_charset}", 'Content-Length' => body.bytesize.to_s, } end
status_code()
click to toggle source
@return [Integer] HTTP status code
# File lib/noise/exception_responder.rb, line 46 def status_code status_symbol = ActionDispatch::ExceptionWrapper.rescue_responses[error.class.name] # calls `status_code` from Rack::Utils Rack::Utils.status_code(status_symbol) end