exception_handler 0.0.15 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c10ea860af8d4f58d6f280fb13b31150b2b8f6b
4
- data.tar.gz: d3ea9573304126e2ca6f79939d172805a050c5eb
3
+ metadata.gz: 3ae7622dbd47f7e8197d2505f478290ea13c191a
4
+ data.tar.gz: 89aa0cb3ce6bb3d3ed54b544b4a08a8bd7074ecc
5
5
  SHA512:
6
- metadata.gz: 7b1dfcc8cb68abd6cf7abc49d4f4aa8cc77c3320fdfca7734954ef6fff2bb1e8206851370c648b92720de210135babc797ce656888a8946a49aa053e667e1ba6
7
- data.tar.gz: 16c1499ceb70db7bb3952b89fd507a33dde54e94f03ca6d4c910bb1b4be54d87540787a7a54fdccfa239640fee7c4233a1242ffb9af50140b5114ca588ddbaad
6
+ metadata.gz: 419c4fc3183648f34bc4092a05500e288d60c4a87367cd8dc3fc0596eea5c7e77069a7b3c8182a6627b6b110f192160db786181a97e20d0863368092c9e2493e
7
+ data.tar.gz: 8586631576b356c745c6ea50c9b15f3bf1439bce588806106a643b1f7002c515d25255c053be123910d1f6410c729ddf65173afa4302968991bda40b2af1f4b0
@@ -1,5 +1,53 @@
1
+ ######################################################
2
+
3
+ require "action_dispatch"
1
4
  require "exception_handler/version"
5
+ require "exception_handler/parser"
6
+
7
+ ######################################################
2
8
 
3
9
  module ExceptionHandler
4
- # Your code goes here...
10
+
11
+ #Hook
12
+ class Engine < ::Rails::Engine
13
+
14
+ #Parsing (story in db / email)
15
+ config.middleware.use 'ErrorHandler::Message'
16
+
17
+ #Custom Pages
18
+ config.exceptions_app = ->(env) { ExceptionController.action(:show).call(env) }
19
+
20
+ end
21
+
22
+ #Middleware
23
+ class Message
24
+
25
+ # Init
26
+ def initialize(app)
27
+ @app = app
28
+ end
29
+
30
+ #Error
31
+ def call(env)
32
+ @app.call(env)
33
+
34
+ rescue Exception => exception
35
+ request = ActionDispatch::Request.new(env)
36
+ controller = env['action_controller.instance']
37
+
38
+ ErrorHandler::Parser.new(exception, request, controller).save unless self.ignore?(exception, request)
39
+ raise exception
40
+ end
41
+
42
+ #Ignore
43
+ def ignore?(exception, request, ignored = {})
44
+ ignored[:errors] = [ActionController::RoutingError, AbstractController::ActionNotFound, ActiveRecord::RecordNotFound]
45
+ ignored[:bots] = /\b(Baidu|Gigabot|Googlebot|libwww-per|lwp-trivial|msnbot|SiteUptime|Slurp|Wordpress|ZIBB|ZyBorg|Yandex|Jyxobot|Huaweisymantecspider|ApptusBot)\b/i
46
+
47
+ return true if ignored[:errors].include?(exception.class) && request.referer.blank?
48
+ return true if request.user_agent =~ ignored[:bots]
49
+ end
50
+
51
+ end
5
52
  end
53
+ end
@@ -0,0 +1,54 @@
1
+ module ErrorHandler
2
+ class Parser
3
+
4
+ #Init
5
+ def initialize(exception, request, controller)
6
+ @exception, @request, @controller = exception, request, controller
7
+ end
8
+
9
+ #Save
10
+ def save
11
+ ActiveRecord::Base.logger.silence do
12
+ Error.create(relevant_info)
13
+ end
14
+ log(relevant_info)
15
+ end
16
+
17
+ #Info
18
+ def relevant_info(info = {})
19
+ info[:class_name] = @exception.class.to_s
20
+ info[:message] = @exception.to_s
21
+ info[:trace] = @exception.backtrace.join("\n")
22
+ info[:target_url] = @request.url
23
+ info[:referer_url] = @request.referer
24
+ info[:params] = @request.params.inspect
25
+ info[:user_agent] = @request.user_agent
26
+ if user
27
+ info[:usable_type] = user[:type]
28
+ info[:usable_id] = user[:id]
29
+ end
30
+ return info
31
+ end
32
+
33
+ #User
34
+ def user(data = {})
35
+ # => refer to Joe's if want to find admin / user
36
+ if(@controller.respond_to?("current_user"))
37
+ user = @controller.send("current_user")
38
+ [:id].each do |field|
39
+ data[:id] = user.send(field) if user.respond_to?(field)
40
+ data[:type] = "user" if @controller.respond_to?("current_user")
41
+ end
42
+ end
43
+ return data
44
+ end
45
+
46
+ #Log
47
+ def log(info)
48
+ message = "#{info[:class_name]} (#{info[:message]}):\n "
49
+ message += Rails.backtrace_cleaner.clean(info[:trace].split("\n")).join("\n")
50
+ Rails.logger.fatal(message)
51
+ end
52
+
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module ExceptionHandler
2
- VERSION = "0.0.15"
3
- end
2
+ VERSION = "0.0.21"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Peck
@@ -55,6 +55,7 @@ files:
55
55
  - Rakefile
56
56
  - exception_handler.gemspec
57
57
  - lib/exception_handler.rb
58
+ - lib/exception_handler/parser.rb
58
59
  - lib/exception_handler/version.rb
59
60
  homepage: http://frontlineutilities.co.uk/ruby-on-rails/exception-handler
60
61
  licenses: