exception_handler 0.7.6.0 → 0.7.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +40 -33
  3. data/.slugignore +7 -7
  4. data/.travis.yml +5 -5
  5. data/Gemfile +13 -13
  6. data/README.md +436 -436
  7. data/Rakefile +7 -7
  8. data/app/assets/stylesheets/exception_handler.css.erb +18 -18
  9. data/app/assets/stylesheets/styles/_base.css.erb +35 -35
  10. data/app/assets/stylesheets/styles/_exception.css.erb +105 -105
  11. data/app/assets/stylesheets/styles/_footer.css.erb +24 -24
  12. data/app/assets/stylesheets/styles/_responsive.css +5 -5
  13. data/app/controllers/exception_handler/exceptions_controller.rb +59 -59
  14. data/app/mailers/exception_handler/exception_mailer.rb +17 -17
  15. data/app/models/exception_handler/exception.rb +199 -191
  16. data/app/views/exception_handler/exceptions/show.html.erb +3 -3
  17. data/app/views/exception_handler/mailers/layout.haml +8 -8
  18. data/app/views/exception_handler/mailers/layout.text.erb +1 -1
  19. data/app/views/exception_handler/mailers/new_exception.erb +4 -4
  20. data/app/views/layouts/exception.html.erb +27 -27
  21. data/config/locales/exception_handler.en.yml +28 -28
  22. data/db/migrate/000000_create_errors.rb +34 -34
  23. data/exception_handler.gemspec +62 -80
  24. data/lib/exception_handler.rb +55 -45
  25. data/lib/exception_handler/config.rb +116 -104
  26. data/lib/exception_handler/engine.rb +70 -61
  27. data/lib/exception_handler/version.rb +25 -0
  28. data/lib/generators/exception_handler/views_generator.rb +33 -33
  29. metadata +7 -71
  30. data/.gitattributes +0 -1
  31. data/.rspec +0 -4
  32. data/LICENSE.txt +0 -22
  33. data/spec/database.yml +0 -3
  34. data/spec/dummy/Rakefile +0 -6
  35. data/spec/dummy/app/assets/config/manifest.js +0 -4
  36. data/spec/dummy/app/assets/images/.keep +0 -0
  37. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  38. data/spec/dummy/app/assets/javascripts/cable.coffee +0 -11
  39. data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
  40. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  41. data/spec/dummy/app/channels/application_cable/channel.rb +0 -5
  42. data/spec/dummy/app/channels/application_cable/connection.rb +0 -5
  43. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  44. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  45. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  46. data/spec/dummy/app/jobs/application_job.rb +0 -2
  47. data/spec/dummy/app/mailers/application_mailer.rb +0 -4
  48. data/spec/dummy/app/models/application_record.rb +0 -3
  49. data/spec/dummy/app/models/concerns/.keep +0 -0
  50. data/spec/dummy/app/views/layouts/application.html.erb +0 -15
  51. data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
  52. data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
  53. data/spec/dummy/bin/bundle +0 -3
  54. data/spec/dummy/bin/rails +0 -4
  55. data/spec/dummy/bin/rake +0 -4
  56. data/spec/dummy/bin/setup +0 -34
  57. data/spec/dummy/bin/update +0 -29
  58. data/spec/dummy/config.ru +0 -8
  59. data/spec/dummy/config/application.rb +0 -21
  60. data/spec/dummy/config/boot.rb +0 -5
  61. data/spec/dummy/config/cable.yml +0 -10
  62. data/spec/dummy/config/database.yml +0 -25
  63. data/spec/dummy/config/environment.rb +0 -5
  64. data/spec/dummy/config/environments/development.rb +0 -62
  65. data/spec/dummy/config/environments/production.rb +0 -87
  66. data/spec/dummy/config/environments/test.rb +0 -42
  67. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +0 -6
  68. data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -6
  69. data/spec/dummy/config/initializers/assets.rb +0 -11
  70. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  71. data/spec/dummy/config/initializers/callback_terminator.rb +0 -6
  72. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -5
  73. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  74. data/spec/dummy/config/initializers/inflections.rb +0 -16
  75. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  76. data/spec/dummy/config/initializers/per_form_csrf_tokens.rb +0 -4
  77. data/spec/dummy/config/initializers/request_forgery_protection.rb +0 -4
  78. data/spec/dummy/config/initializers/session_store.rb +0 -3
  79. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  80. data/spec/dummy/config/locales/en.yml +0 -23
  81. data/spec/dummy/config/puma.rb +0 -47
  82. data/spec/dummy/config/routes.rb +0 -6
  83. data/spec/dummy/config/secrets.yml +0 -22
  84. data/spec/dummy/lib/assets/.keep +0 -0
  85. data/spec/dummy/log/.keep +0 -0
  86. data/spec/dummy/public/404.html +0 -67
  87. data/spec/dummy/public/422.html +0 -67
  88. data/spec/dummy/public/500.html +0 -66
  89. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  90. data/spec/dummy/public/apple-touch-icon.png +0 -0
  91. data/spec/dummy/public/favicon.ico +0 -0
  92. data/spec/exception_handler.rb +0 -22
  93. data/spec/exception_handler/exception_controller_spec.rb +0 -18
  94. data/spec/spec_helper.rb +0 -55
@@ -1,17 +1,17 @@
1
- module ExceptionHandler
2
- class ExceptionMailer < ActionMailer::Base
3
-
4
- # Layout
5
- layout "mailers/layouts/mailer"
6
-
7
- # Defaults
8
- default from: ExceptionHandler.config.email
9
- default template_path: "exception_handler/mailers" # => http://stackoverflow.com/a/18579046/1143732
10
-
11
- def new_exception e
12
- @exception = e
13
- mail to: ExceptionHandler.config.email
14
- Rails.logger.info "Exception Sent To → #{ExceptionHandler.config.email}"
15
- end
16
- end
17
- end
1
+ module ExceptionHandler
2
+ class ExceptionMailer < ActionMailer::Base
3
+
4
+ # Layout
5
+ layout "mailer"
6
+
7
+ # Defaults
8
+ default from: ExceptionHandler.config.email
9
+ default template_path: "exception_handler/mailers" # => http://stackoverflow.com/a/18579046/1143732
10
+
11
+ def new_exception e
12
+ @exception = e
13
+ mail to: ExceptionHandler.config.email
14
+ Rails.logger.info "Exception Sent To → #{ExceptionHandler.config.email}"
15
+ end
16
+ end
17
+ end
@@ -1,191 +1,199 @@
1
- module ExceptionHandler
2
-
3
- ############################################################
4
- ############################################################
5
-
6
- # => Search Bots
7
- # => Used in "Exception" class
8
- BOTS = %w(Baidu Gigabot Googlebot libwww-per lwp-trivial msnbot SiteUptime Slurp Wordpress ZIBB ZyBorg Yandex Jyxobot Huaweisymantecspider ApptusBot)
9
-
10
- # => Attributes
11
- # => Determine schema etc
12
- ATTRS = %i(class_name status message trace target referrer params user_agent)
13
-
14
- ############################################################
15
- ############################################################
16
-
17
- # => Class (inheritance dependent on whether db option is available)
18
- self::Exception = Class.new (ExceptionHandler.config.try(:db) ? ActiveRecord::Base : Object) do
19
-
20
- # => Include individual elements
21
- # => Only required if no db present (no ActiveRecord)
22
- if ExceptionHandler.config.try(:db)
23
-
24
- # => Set Attrs
25
- def initialize attributes={}
26
- super
27
- ATTRS.each do |type|
28
- self[type] = eval type.to_s
29
- end
30
- end
31
-
32
- else
33
-
34
- # => AciveModel
35
- include ActiveModel::Model
36
- include ActiveModel::Validations
37
-
38
- # => Callback Extension
39
- extend ActiveModel::Callbacks
40
- define_model_callbacks :initialize, only: :after
41
-
42
- # => Initialize
43
- # => http://api.rubyonrails.org/classes/ActiveModel/Callbacks.html
44
- # => http://stackoverflow.com/a/17682228/1143732
45
- def initialize attributes={}
46
- super
47
- run_callbacks :initialize do
48
- # => Needed for after_initialize
49
- end
50
- end
51
-
52
- end
53
-
54
- ##################################
55
- ##################################
56
-
57
- ####################
58
- # Table #
59
- ####################
60
-
61
- # Schema
62
- ###################
63
- # class_name @exception.class.name
64
- # status ActionDispatch::ExceptionWrapper.new(@request.env, @exception).status_code
65
- # message @exception.message
66
- # trace @exception.backtrace.join("\n")
67
- # target @request.url
68
- # referer @request.referer
69
- # params @request.params.inspect
70
- # user_agent @request.user_agent
71
- # created_at
72
- # updated_at
73
-
74
- # => Table is called "errors"
75
- # => Dev needs to use migration to create db
76
- if ExceptionHandler.config.try(:db)
77
- def self.table_name
78
- ExceptionHandler.config.db
79
- end
80
- end
81
-
82
- ##################################
83
- ##################################
84
-
85
- ####################
86
- # Options #
87
- ####################
88
-
89
- # => Email
90
- # => after_initialize invoked after .new method called
91
- # => Should have been after_create but user may not save
92
- after_initialize Proc.new { |e| ExceptionHandler::ExceptionMailer.new_exception(e).deliver } if ExceptionHandler.config.try(:email).try(:is_a?, String)
93
-
94
- # => Attributes
95
- attr_accessor :request, :klass, :exception, :description
96
- attr_accessor *ATTRS unless ExceptionHandler.config.try(:db)
97
-
98
- # => Validations
99
- validates :klass, exclusion: { in: [ActionController::RoutingError, AbstractController::ActionNotFound, ActiveRecord::RecordNotFound], message: "%{value}" }, if: -> { referer.blank? } # => might need full Proc syntax
100
- validates :user_agent, format: { without: Regexp.new( BOTS.join("|"), Regexp::IGNORECASE ) }
101
-
102
- ##################################
103
- ##################################
104
-
105
- ####################################
106
- # Virtual
107
- ####################################
108
-
109
- # => Klass
110
- # => Used for validation (needs to be cleaned up in 0.7.0)
111
- def klass
112
- exception.class
113
- end
114
-
115
- # => Exception (virtual)
116
- def exception
117
- request.env['action_dispatch.exception']
118
- end
119
-
120
- # => Description
121
- def description
122
- I18n.with_options scope: [:exception_handler], message: message, status: status do |i18n|
123
- i18n.t response, default: Rack::Utils::HTTP_STATUS_CODES[status] || status
124
- end
125
- end
126
-
127
- ####################################
128
- # Exception
129
- ####################################
130
-
131
- # => Class Name
132
- def class_name
133
- exception.class.name
134
- end
135
-
136
- # => Message
137
- def message
138
- exception.message
139
- end
140
-
141
- # => Trace
142
- def trace
143
- exception.backtrace.join("\n")
144
- end
145
-
146
- ####################################
147
- # Request
148
- ####################################
149
-
150
- # => Target URL
151
- def target
152
- request.url
153
- end
154
-
155
- # => Referrer URL
156
- def referer
157
- request.referer
158
- end
159
-
160
- # => Params
161
- def params
162
- request.params.inspect
163
- end
164
-
165
- # => User Agent
166
- def user_agent
167
- request.user_agent
168
- end
169
-
170
- ####################################
171
- # Other
172
- ####################################
173
-
174
- # => Status code (404, 500 etc)
175
- def status
176
- ActionDispatch::ExceptionWrapper.new(request.env, exception).status_code
177
- end
178
-
179
- # => Server Response ("Not Found" etc)
180
- def response
181
- ActionDispatch::ExceptionWrapper.rescue_responses[class_name]
182
- end
183
-
184
- ##################################
185
- ##################################
186
-
187
- end
188
- end
189
-
190
- ############################################################
191
- ############################################################
1
+ module ExceptionHandler
2
+
3
+ ############################################################
4
+ ############################################################
5
+
6
+ # => Search Bots
7
+ # => Used in "Exception" class
8
+ BOTS = %w(Baidu Gigabot Googlebot libwww-per lwp-trivial msnbot SiteUptime Slurp Wordpress ZIBB ZyBorg Yandex Jyxobot Huaweisymantecspider ApptusBot)
9
+
10
+ # => Attributes
11
+ # => Determine schema etc
12
+ ATTRS = %i(class_name status message trace target referrer params user_agent)
13
+
14
+ # => Exceptions to be rescued by ExceptionHandler
15
+ EXCEPTIONS_TO_BE_RESCUED = [ActionController::RoutingError, AbstractController::ActionNotFound].tap do |list|
16
+ list << ActiveRecord::RecordNotFound if defined?(ActiveRecord)
17
+ list << Mongoid::Errors::DocumentNotFound if defined?(Mongoid)
18
+ end
19
+
20
+ ############################################################
21
+ ############################################################
22
+
23
+ # => Class (inheritance dependent on whether db option is available)
24
+ self::Exception = Class.new(
25
+ (ExceptionHandler.config.try(:db) && defined?(ActiveRecord)) ? ActiveRecord::Base : Object
26
+ ) do
27
+
28
+ # => Include individual elements
29
+ # => Only required if no db present (no ActiveRecord)
30
+ if ExceptionHandler.config.try(:db)
31
+
32
+ # => Set Attrs
33
+ def initialize attributes={}
34
+ super
35
+ ATTRS.each do |type|
36
+ self[type] = eval type.to_s
37
+ end
38
+ end
39
+
40
+ else
41
+
42
+ # => ActiveModel
43
+ include ActiveModel::Model
44
+ include ActiveModel::Validations
45
+
46
+ # => Callback Extension
47
+ extend ActiveModel::Callbacks
48
+ define_model_callbacks :initialize, only: :after
49
+
50
+ # => Initialize
51
+ # => http://api.rubyonrails.org/classes/ActiveModel/Callbacks.html
52
+ # => http://stackoverflow.com/a/17682228/1143732
53
+ def initialize attributes={}
54
+ super
55
+ run_callbacks :initialize do
56
+ # => Needed for after_initialize
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ ##################################
63
+ ##################################
64
+
65
+ ####################
66
+ # Table #
67
+ ####################
68
+
69
+ # Schema
70
+ ###################
71
+ # class_name @exception.class.name
72
+ # status ActionDispatch::ExceptionWrapper.new(@request.env, @exception).status_code
73
+ # message @exception.message
74
+ # trace @exception.backtrace.join("\n")
75
+ # target @request.url
76
+ # referer @request.referer
77
+ # params @request.params.inspect
78
+ # user_agent @request.user_agent
79
+ # created_at
80
+ # updated_at
81
+
82
+ # => Table is called "errors"
83
+ # => Dev needs to use migration to create db
84
+ if ExceptionHandler.config.try(:db)
85
+ def self.table_name
86
+ ExceptionHandler.config.db
87
+ end
88
+ end
89
+
90
+ ##################################
91
+ ##################################
92
+
93
+ ####################
94
+ # Options #
95
+ ####################
96
+
97
+ # => Email
98
+ # => after_initialize invoked after .new method called
99
+ # => Should have been after_create but user may not save
100
+ after_initialize Proc.new { |e| ExceptionHandler::ExceptionMailer.new_exception(e).deliver } if ExceptionHandler.config.try(:email).try(:is_a?, String)
101
+
102
+ # => Attributes
103
+ attr_accessor :request, :klass, :exception, :description
104
+ attr_accessor *ATTRS unless ExceptionHandler.config.try(:db)
105
+
106
+ # => Validations
107
+ validates :klass, exclusion: { in: EXCEPTIONS_TO_BE_RESCUED, message: "%{value}" }, if: -> { referer.blank? } # => might need full Proc syntax
108
+ validates :user_agent, format: { without: Regexp.new( BOTS.join("|"), Regexp::IGNORECASE ) }
109
+
110
+ ##################################
111
+ ##################################
112
+
113
+ ####################################
114
+ # Virtual
115
+ ####################################
116
+
117
+ # => Klass
118
+ # => Used for validation (needs to be cleaned up in 0.7.0)
119
+ def klass
120
+ exception.class
121
+ end
122
+
123
+ # => Exception (virtual)
124
+ def exception
125
+ request.env['action_dispatch.exception']
126
+ end
127
+
128
+ # => Description
129
+ def description
130
+ I18n.with_options scope: [:exception_handler], message: message, status: status do |i18n|
131
+ i18n.t response, default: Rack::Utils::HTTP_STATUS_CODES[status] || status
132
+ end
133
+ end
134
+
135
+ ####################################
136
+ # Exception
137
+ ####################################
138
+
139
+ # => Class Name
140
+ def class_name
141
+ exception.class.name
142
+ end
143
+
144
+ # => Message
145
+ def message
146
+ exception.message
147
+ end
148
+
149
+ # => Trace
150
+ def trace
151
+ exception.backtrace.join("\n")
152
+ end
153
+
154
+ ####################################
155
+ # Request
156
+ ####################################
157
+
158
+ # => Target URL
159
+ def target
160
+ request.url
161
+ end
162
+
163
+ # => Referrer URL
164
+ def referer
165
+ request.referer
166
+ end
167
+
168
+ # => Params
169
+ def params
170
+ request.params.inspect
171
+ end
172
+
173
+ # => User Agent
174
+ def user_agent
175
+ request.user_agent
176
+ end
177
+
178
+ ####################################
179
+ # Other
180
+ ####################################
181
+
182
+ # => Status code (404, 500 etc)
183
+ def status
184
+ ActionDispatch::ExceptionWrapper.new(request.env, exception).status_code
185
+ end
186
+
187
+ # => Server Response ("Not Found" etc)
188
+ def response
189
+ ActionDispatch::ExceptionWrapper.rescue_responses[class_name]
190
+ end
191
+
192
+ ##################################
193
+ ##################################
194
+
195
+ end
196
+ end
197
+
198
+ ############################################################
199
+ ############################################################
@@ -1,3 +1,3 @@
1
- <%= content_tag :div, class: "exception", data: { status: @exception.status, response: @exception.response.to_s.humanize, rails: Rails.version }, onclick: ("location.href=\"#{root_url}\";" if @exception.status == "500" && Rails.application.routes.recognize_path("/")), title: ("Return Home" if @exception.status == "500" && Rails.application.routes.recognize_path("/")) do %>
2
- <%= content_tag :span, @exception.description.html_safe %>
3
- <% end %>
1
+ <%= content_tag :div, class: "exception", data: { status: @exception.status, response: @exception.response.to_s.humanize, rails: Rails.version }, onclick: ("location.href=\"#{root_url}\";" if @exception.status == "500" && Rails.application.routes.recognize_path("/")), title: ("Return Home" if @exception.status == "500" && Rails.application.routes.recognize_path("/")) do %>
2
+ <%= content_tag :span, @exception.description.html_safe %>
3
+ <% end %>
@@ -1,8 +1,8 @@
1
- !!!
2
- %html
3
- %head
4
- %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
5
- :css
6
- /* Email styles need to be inline */
7
- %body
8
- = yield
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
5
+ :css
6
+ /* Email styles need to be inline */
7
+ %body
8
+ = yield
@@ -1 +1 @@
1
- <%= yield %>
1
+ <%= yield %>