class Rambulance::ExceptionsApp
Public Class Methods
call(env)
click to toggle source
# File lib/rambulance/exceptions_app.rb, line 31 def self.call(env) exception = env["action_dispatch.exception"] status_in_words = if exception ActionDispatch::ExceptionWrapper.rescue_responses[exception.class.to_s] else env["PATH_INFO"][1..-1].to_sym.tap do |_status_in_words| env["PATH_INFO"] = "/#{Rack::Utils::SYMBOL_TO_STATUS_CODE[_status_in_words]}" end end if exception.nil? && status_in_words == :unprocessable_entity [302, { "Location" => "/rambulance/unprocessable_content" }, [""]] else action(status_in_words).call(env) end end
local_prefixes()
click to toggle source
# File lib/rambulance/exceptions_app.rb, line 48 def self.local_prefixes [Rambulance.view_path] end
Public Instance Methods
process(action, *args)
click to toggle source
Calls superclass method
# File lib/rambulance/exceptions_app.rb, line 66 def process(action, *args) if action.to_s.empty? action = request.env["PATH_INFO"][1..-1].to_sym request.env["PATH_INFO"] = "/#{Rack::Utils::SYMBOL_TO_STATUS_CODE[action]}" end super end
unprocessable_entity()
click to toggle source
# File lib/rambulance/exceptions_app.rb, line 60 def unprocessable_entity unprocessable_content_path = error_path(:unprocessable_content) render(template_exists?(unprocessable_content_path) ? unprocessable_content_path : error_path(:internal_server_error)) end
Private Instance Methods
controller_path()
click to toggle source
# File lib/rambulance/exceptions_app.rb, line 136 def controller_path Rambulance.view_path end
error_path(status_in_words = status_in_words())
click to toggle source
# File lib/rambulance/exceptions_app.rb, line 128 def error_path(status_in_words = status_in_words()) "#{controller_path}/#{status_in_words}" end
exception()
click to toggle source
# File lib/rambulance/exceptions_app.rb, line 124 def exception request.env["action_dispatch.exception"] end
layout_name()
click to toggle source
# File lib/rambulance/exceptions_app.rb, line 132 def layout_name request.format.json? ? false : Rambulance.layout_name end
process_action(*)
click to toggle source
Calls superclass method
# File lib/rambulance/exceptions_app.rb, line 77 def process_action(*) begin request.content_mime_type rescue Mime::Type::InvalidMimeType request.env["MALFORMED_CONTENT_TYPE"], request.env["CONTENT_TYPE"] = request.env["CONTENT_TYPE"], "text/plain" end begin request.GET rescue ActionController::BadRequest request.env["MALFORMED_QUERY_STRING"], request.env["QUERY_STRING"] = request.env["QUERY_STRING"], "" end begin request.POST rescue *BAD_REQUEST_ERRORS request.env["MALFORMED_BODY"], request.env["rack.input"] = request.env["rack.input"], StringIO.new end begin request.accepts rescue Mime::Type::InvalidMimeType request.env["MALFORMED_HTTP_ACCEPT"], request.env["HTTP_ACCEPT"] = request.env["HTTP_ACCEPT"], "*/*" end if defined?(Rack::RACK_REQUEST_FORM_ERROR) && request.env.include?(Rack::RACK_REQUEST_FORM_ERROR) request.env.delete(Rack::RACK_REQUEST_FORM_ERROR) end # The #formats method needs to be called after the sanitization above. request.formats << Mime::Type.lookup('text/plain') super end
send_action(name, *args)
click to toggle source
Calls superclass method
# File lib/rambulance/exceptions_app.rb, line 112 def send_action(name, *args) @_status = request.env["PATH_INFO"][1..-1].to_i @_response.status = @_status @_body = { :status => @_status, :error => Rack::Utils::HTTP_STATUS_CODES.fetch(@_status.to_i, Rack::Utils::HTTP_STATUS_CODES[500]) } super end
status_in_words()
click to toggle source
# File lib/rambulance/exceptions_app.rb, line 120 def status_in_words ERROR_HTTP_STATUSES[status.to_i] end