On Fri, Dec 3, 2010 at 3:27 PM, tom [email protected] wrote:
so what im asking his how u guys handle those situations.
Someone might come along with a better idea and this is something that I
picked up elsewhere and cant really take credit for, but I put something
like this in my application controller which globally handles this kind
of
thing — as well as other unhandled errors. I prefer to throw my errors
into a db table just because I find it easier to review and reference
than a
log…
rescue_from Exception, :with => :rescue_all_exceptions if Rails.env ==
‘production’
def rescue_all_exceptions(exception)
case exception
when ActiveRecord::RecordNotFound
render :text => “
The requested record
was
not found
”, :layout => “application”, :status => :not_found
when ActionController::RoutingError,
ActionController::UnknownController, ActionController::UnknownAction
render :text => “
The request made was
invalid
”, :layout => “application”, :status => :not_found
else
begin
SystemError.new(:user_id => nil,
:account_id => nil,
:location => nil,
:error => “Undefined exception”,
:incidentals => { “controller_name” =>
controller_name || “”,
“action_name” => action_name
||
“”,
“request.request_uri” =>
request.request_uri || “”,
“request.method” =>
request.method || “”,
“request.path” =>
request.path
|| “”,
“request.parameters.inspect”
=>
request.parameters.inspect || “”,
“exception.message” =>
exception.message || “”,
“exception.clean_backtrace”
=>
exception.clean_backtrace || “” }
).save
rescue
# worst case we save it to the error logger
logger.error( “\nWhile processing a #{request.method} request
on
#{request.path}\n
parameters: #{request.parameters.inspect}\n
#{exception.message}\n#{exception.backtrace.join( “\n” )}\n\n”
)
end
render :text => “
An internal error
occurred. Sorry for the inconvenience
”, :layout => “application”,
:status => :internal_server_error
end
end