Class: Rambulance::ExceptionsApp

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/rambulance/exceptions_app.rb

Direct Known Subclasses

ExceptionsApp

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(env) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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_prefixesObject



48
49
50
# File 'lib/rambulance/exceptions_app.rb', line 48

def self.local_prefixes
  [Rambulance.view_path]
end

Instance Method Details

#process(action, *args) ⇒ Object



66
67
68
69
70
71
72
73
# 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_entityObject



60
61
62
63
64
# 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