lib/rambulance/exceptions_app.rb in rambulance-0.3.0 vs lib/rambulance/exceptions_app.rb in rambulance-0.3.1
- old
+ new
@@ -8,10 +8,16 @@
end.invert
class ExceptionsApp < ActionController::Base
layout :layout_name
+ BAD_REQUEST_EXCEPTION = begin
+ ActionController::BadRequest
+ rescue NameError
+ TypeError # Rails 3.2 doesn't know about ActionController::BadRequest
+ end
+
def self.call(env)
exception = env["action_dispatch.exception"]
status_in_words = if exception
ActionDispatch::ExceptionWrapper.rescue_responses[exception.class.to_s]
else
@@ -38,11 +44,11 @@
private
def process_action(*)
begin
request.GET
- rescue bad_request_exception
+ rescue BAD_REQUEST_EXCEPTION
env["MALFORMED_QUERY_STRING"], env["QUERY_STRING"] = env["QUERY_STRING"], ""
end
super
end
@@ -66,20 +72,14 @@
def error_path(status_in_words = status_in_words())
"#{controller_path}/#{status_in_words}"
end
def layout_name
- Rambulance.layout_name
+ request.format.json? ? false : Rambulance.layout_name
end
def controller_path
Rambulance.view_path
- end
-
- def bad_request_exception
- ActionController::BadRequest
- rescue NameError
- TypeError # Rails 3.2 doesn't know about ActionController::BadRequest
end
helper_method :status_in_words, :exception
end
end