lib/flail/exception.rb in flail-0.0.3 vs lib/flail/exception.rb in flail-0.0.4
- old
+ new
@@ -1,10 +1,11 @@
require 'socket'
+require 'json'
class Flail
class Exception
- def initialize(env, exception)
+ def initialize(env, exception, local = false)
@exception = exception
@env = env
end
#
@@ -16,26 +17,22 @@
else
ActionDispatch::Request.new(@env)
end
end
- def controller
- @controller ||= @env['action_controller.instance']
- @controller ||= @request.controller if @request.respond_to?(:controller)
+ def request_data
+ @request_data ||= if @env['flail.request.data']
+ @env['flail.request.data']
+ else
+ {
+ :parameters => {},
+ :user => {},
+ }
+ end
end
- def user
- if controller.respond_to?(:current_user)
- current_user = controller.current_user
- {:id => current_user.id, :name => current_user.to_s}
- else
- {}
- end
- end
-
-
#
# Handling the exception
#
def handle!
Flail.swing(self.extract.to_json) unless self.ignore?
@@ -43,17 +40,20 @@
def extract
@extract ||= begin
info = {}
- info[:class_name] = @exception.class.to_s # @exception class
- info[:message] = @exception.to_s # error message
- info[:trace] = @exception.backtrace.to_json # backtrace of error
- info[:target_url] = request.url # url of request
- info[:referer_url] = request.referer # referer
- info[:parameters] = request.params.to_json # request parameters
- info[:user_agent] = request.user_agent # user agent
- info[:user] = self.user.to_json # current user
+ # rack env
+ info[:rack] = @env.to_json(:except => ['flail.request', 'flail.request.data'])
+ info[:class_name] = @exception.class.to_s # @exception class
+ info[:message] = @exception.to_s # error message
+ info[:trace] = @exception.backtrace # backtrace of error
+ info[:target_url] = request_data[:target_url] # url of request
+ info[:referer_url] = request_data[:referer_url] # referer
+ info[:parameters] = request_data[:parameters] # request parameters
+ info[:user_agent] = request_data[:user_agent] # user agent
+ info[:user] = request_data[:user] # current user
+ info[:session_data]= request_data[:session_data] # session
# special variables
info[:environment] = Flail.configuration.env
info[:hostname] = Flail.configuration.hostname
info[:tag] = Flail.configuration.tag