I am trying to create custom error pages in a project of rails 3.0.20 and ruby 1.8.7.
Anyway in my application controller:
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, :with => :render_error
rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, :with => :render_error_not_found
end
Then the render error method:
def render_error(exception)
notify_airbrake(exception)
Rails.logger.fatal exception
Rails.logger.fatal exception.backtrace.join("\n")
respond_to do |format|
format.html { render :template => "errors/error_500", :layout => 'layouts/application'}
format.all { render :nothing => true, :status => 500 }
end
end
It seems that now my logs are being filled with a much longer then usual backtrace. Why is that happening? Is there a way to show just the "important" part of a backtrace? And is it correct to call airbrake here?
Thanks
Check out http://api.rubyonrails.org/classes/ActiveSupport/BacktraceCleaner.html. Rails uses this to clean up your backrace before display.
You could use it like this:
Rails.backtrace_cleaner.clean(exception.backtrace)
I'm actually looking in the rails source code, because I thought your exception might have been cleaned already by the time it gets to your render_error method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With