lib/bugsnag/rails/controller_methods.rb in bugsnag-1.1.5 vs lib/bugsnag/rails/controller_methods.rb in bugsnag-1.2.0.beta

- old
+ new

@@ -1,64 +1,48 @@ -module Bugsnag - module Rails - module ControllerMethods - private - def notify_bugsnag(exception, custom_data=nil) - request_data = bugsnag_request_data - request_data[:meta_data][:custom] = custom_data if custom_data - Bugsnag.notify(exception, request_data) +module Bugsnag::Rails + module ControllerMethods + def self.included(base) + base.extend ClassMethods + end + + module ClassMethods + private + def before_bugsnag_notify(*methods, &block) + _add_bugsnag_notify_callback(:rails_before_callbacks, *methods, &block) end - def bugsnag_request_data - { - :user_id => bugsnag_session_id, - :context => Bugsnag::Helpers.param_context(params), - :meta_data => { - :request => { - :url => bugsnag_request_url, - :controller => params[:controller], - :action => params[:action], - :params => bugsnag_filter_if_filtering(Bugsnag::Helpers.cleanup_hash(params.to_hash)), - }, - :session => bugsnag_filter_if_filtering(Bugsnag::Helpers.cleanup_hash(bugsnag_session_data)), - :environment => bugsnag_filter_if_filtering(Bugsnag::Helpers.cleanup_hash(request.env)) - } - } + def after_bugsnag_notify(*methods, &block) + _add_bugsnag_notify_callback(:rails_after_callbacks, *methods, &block) end - def bugsnag_session_id - session = bugsnag_session_data - session[:session_id] || session["session_id"] - end - - def bugsnag_request_url - url = "#{request.protocol}#{request.host}" + def _add_bugsnag_notify_callback(callback_key, *methods, &block) + options = methods.last.is_a?(Hash) ? methods.pop : {} - unless [80, 443].include?(request.port) - url << ":#{request.port}" - end + before_filter(options) do |controller| + request_data = Bugsnag.configuration.request_data + request_data[callback_key] ||= [] - url << request.fullpath - url - end + # Set up "method symbol" callbacks + methods.each do |method_symbol| + request_data[callback_key] << lambda { |notification| + self.send(method_symbol, notification) + } + end - def bugsnag_session_data - if session.respond_to?(:to_hash) - session.to_hash - else - session.data + # Set up "block" callbacks + request_data[callback_key] << lambda { |notification| + controller.instance_exec(notification, &block) + } if block_given? end end - - def bugsnag_filter_if_filtering(hash) - return hash if ! hash.is_a?(Hash) + end - if respond_to?(:filter_parameters) - filter_parameters(hash) rescue hash - else - hash - end - end + private + def notify_bugsnag(exception, custom_data=nil) + Bugsnag.warn "DEPRECATED METHOD: notify_bugsnag is deprecated and will be removed in the future. Please use Bugsnag.notify instead" if Bugsnag.configuration.release_stage != "production" + overrides = {} + overrides[:custom] = custom_data if custom_data + Bugsnag.notify(exception, overrides) end end end \ No newline at end of file