lib/airbrake/rails/controller_methods.rb in airbrake-4.3.1 vs lib/airbrake/rails/controller_methods.rb in airbrake-4.3.2

- old
+ new

@@ -1,23 +1,33 @@ module Airbrake module Rails module ControllerMethods + SLASH = "/" + def airbrake_request_data { - :parameters => airbrake_filter_if_filtering(params.to_hash), + :parameters => airbrake_filter_if_filtering(to_hash(params)), :session_data => airbrake_filter_if_filtering(airbrake_session_data), :controller => params[:controller], :action => params[:action], :url => airbrake_request_url, :cgi_data => airbrake_filter_if_filtering(request.env), - :user => airbrake_current_user || {} + :user => airbrake_current_user } end private + def to_hash(params) + # Rails <= 4 + return params.to_hash if params.respond_to?(:to_hash) + + # Rails >= 5 + params.to_unsafe_h + end + # This method should be used for sending manual notifications while you are still # inside the controller. Otherwise it works like Airbrake.notify. def notify_airbrake(hash_or_exception) unless airbrake_local_request? Airbrake.notify_or_ignore(hash_or_exception, airbrake_request_data) @@ -88,21 +98,31 @@ unless [80, 443].include?(request.port) url << ":#{request.port}" end - URI.join(url, request.fullpath).to_s + unless request.fullpath[0] == SLASH + url << SLASH + end + + url << request.fullpath end def airbrake_current_user user = fetch_user if user Airbrake.configuration.user_attributes.map(&:to_sym).inject({}) do |hsh, attr| - hsh[attr.to_sym] = user.send(attr) if user.respond_to? attr - hsh + begin + hsh[attr] = user.send(attr) if user.respond_to? attr + hsh + rescue + hsh + end end + else + {} end end def fetch_user if defined?(current_user) @@ -110,9 +130,11 @@ elsif defined?(current_member) current_member else nil end + rescue + nil ensure # The Airbrake middleware is first in the chain, before ActiveRecord::ConnectionAdapters::ConnectionManagement # kicks in to do its thing. This can cause the connection pool to run out of connections. if defined?(ActiveRecord::Base) && ActiveRecord::Base.respond_to?(:connection_pool) ActiveRecord::Base.connection_pool.release_connection