exception_handler 0.7.5 → 0.8.0.1

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 (109) hide show
  1. checksums.yaml +5 -5
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +51 -33
  4. data/.rspec +3 -4
  5. data/.slugignore +7 -0
  6. data/.travis.yml +13 -5
  7. data/Gemfile +16 -13
  8. data/README.md +643 -443
  9. data/Rakefile +7 -7
  10. data/app/assets/stylesheets/exception_handler.css.erb +23 -18
  11. data/app/assets/stylesheets/styles/_base.css.erb +28 -35
  12. data/app/assets/stylesheets/styles/_exception.css.erb +106 -105
  13. data/app/assets/stylesheets/styles/_footer.css.erb +24 -24
  14. data/app/assets/stylesheets/styles/_responsive.css +5 -5
  15. data/app/controllers/exception_handler/exceptions_controller.rb +66 -55
  16. data/app/mailers/exception_handler/exception_mailer.rb +17 -17
  17. data/app/models/exception_handler/exception.rb +200 -191
  18. data/app/views/exception_handler/exceptions/show.html.erb +3 -3
  19. data/app/views/exception_handler/mailers/layout.haml +8 -8
  20. data/app/views/exception_handler/mailers/layout.text.erb +1 -1
  21. data/app/views/exception_handler/mailers/new_exception.erb +4 -4
  22. data/app/views/layouts/exception.html.erb +32 -27
  23. data/app/views/layouts/mailer.html.erb +5 -0
  24. data/app/views/layouts/mailer.text.erb +1 -0
  25. data/config/locales/exception_handler.en.yml +28 -29
  26. data/config/routes.rb +42 -0
  27. data/db/migrate/000000_create_errors.rb +34 -34
  28. data/exception_handler.gemspec +64 -80
  29. data/lib/exception_handler.rb +56 -45
  30. data/lib/exception_handler/config.rb +185 -103
  31. data/lib/exception_handler/engine.rb +78 -60
  32. data/lib/exception_handler/version.rb +25 -0
  33. data/lib/generators/exception_handler/views_generator.rb +33 -33
  34. data/spec/controllers/controller_spec.rb +107 -0
  35. data/spec/dummy/.rspec +1 -0
  36. data/spec/dummy/.ruby-version +1 -0
  37. data/spec/dummy/Rakefile +6 -6
  38. data/spec/dummy/app/assets/config/manifest.js +3 -4
  39. data/spec/dummy/app/assets/javascripts/application.js +15 -13
  40. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  41. data/spec/dummy/app/assets/stylesheets/application.css +15 -15
  42. data/spec/dummy/app/channels/application_cable/channel.rb +4 -5
  43. data/spec/dummy/app/channels/application_cable/connection.rb +4 -5
  44. data/spec/dummy/app/controllers/application_controller.rb +2 -5
  45. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  46. data/spec/dummy/app/jobs/application_job.rb +2 -2
  47. data/spec/dummy/app/mailers/application_mailer.rb +4 -4
  48. data/spec/dummy/app/models/application_record.rb +3 -3
  49. data/spec/dummy/app/views/layouts/application.html.erb +15 -15
  50. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -13
  51. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -1
  52. data/spec/dummy/bin/bundle +3 -3
  53. data/spec/dummy/bin/rails +4 -4
  54. data/spec/dummy/bin/rake +4 -4
  55. data/spec/dummy/bin/setup +36 -34
  56. data/spec/dummy/bin/update +31 -29
  57. data/spec/dummy/bin/yarn +11 -0
  58. data/spec/dummy/config.ru +5 -8
  59. data/spec/dummy/config/application.rb +18 -21
  60. data/spec/dummy/config/boot.rb +5 -5
  61. data/spec/dummy/config/cable.yml +10 -10
  62. data/spec/dummy/config/database.yml +25 -25
  63. data/spec/dummy/config/environment.rb +5 -5
  64. data/spec/dummy/config/environments/development.rb +61 -62
  65. data/spec/dummy/config/environments/production.rb +94 -87
  66. data/spec/dummy/config/environments/test.rb +46 -42
  67. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -6
  68. data/spec/dummy/config/initializers/assets.rb +14 -11
  69. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  70. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  71. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -5
  72. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
  73. data/spec/dummy/config/initializers/inflections.rb +16 -16
  74. data/spec/dummy/config/initializers/mime_types.rb +4 -4
  75. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  76. data/spec/dummy/config/locales/en.yml +33 -23
  77. data/spec/dummy/config/puma.rb +34 -47
  78. data/spec/dummy/config/routes.rb +3 -6
  79. data/spec/dummy/config/storage.yml +34 -0
  80. data/spec/dummy/package.json +5 -0
  81. data/spec/dummy/public/404.html +67 -67
  82. data/spec/dummy/public/422.html +67 -67
  83. data/spec/dummy/public/500.html +66 -66
  84. data/spec/dummy/spec/rails_helper.rb +57 -0
  85. data/spec/dummy/spec/spec_helper.rb +100 -0
  86. data/spec/dummy/storage/.keep +0 -0
  87. data/spec/features/asset_spec.rb +61 -0
  88. data/spec/features/config_spec.rb +51 -0
  89. data/spec/features/engine_spec.rb +180 -0
  90. data/spec/mailers/mailer_spec.rb +26 -0
  91. data/spec/models/model_spec.rb +26 -0
  92. data/spec/routing/routing_spec.rb +85 -0
  93. data/spec/spec_helper.rb +101 -55
  94. data/spec/views/views_spec.rb +29 -0
  95. metadata +54 -28
  96. data/.gitattributes +0 -1
  97. data/LICENSE.txt +0 -22
  98. data/app/assets/images/exception_handler/bg.jpg +0 -0
  99. data/app/assets/images/exception_handler/bg_overlay.png +0 -0
  100. data/spec/database.yml +0 -3
  101. data/spec/dummy/app/assets/javascripts/cable.coffee +0 -11
  102. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +0 -6
  103. data/spec/dummy/config/initializers/callback_terminator.rb +0 -6
  104. data/spec/dummy/config/initializers/per_form_csrf_tokens.rb +0 -4
  105. data/spec/dummy/config/initializers/request_forgery_protection.rb +0 -4
  106. data/spec/dummy/config/initializers/session_store.rb +0 -3
  107. data/spec/dummy/config/secrets.yml +0 -22
  108. data/spec/exception_handler.rb +0 -22
  109. data/spec/exception_handler/exception_controller_spec.rb +0 -18
@@ -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,200 @@
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?"
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
+ ############################################################
15
+ ############################################################
16
+
17
+ # => Class (inheritance dependent on whether db option is available)
18
+ self::Exception =
19
+ Class.new( (ExceptionHandler.config.try(:db) && defined?(ActiveRecord)) ? ActiveRecord::Base : Object ) do
20
+
21
+ # => Include individual elements
22
+ # => Only required if no db present (no ActiveRecord)
23
+ if ExceptionHandler.config.try(:db)
24
+
25
+ # => Set Attrs
26
+ def initialize attributes={}
27
+ super
28
+ ATTRS.each do |type|
29
+ self[type] = eval type.to_s
30
+ end
31
+ end
32
+
33
+ else
34
+
35
+ # => ActiveModel
36
+ include ActiveModel::Model
37
+ include ActiveModel::Validations
38
+
39
+ # => Callback Extension
40
+ extend ActiveModel::Callbacks
41
+ define_model_callbacks :initialize, only: :after
42
+
43
+ # => Initialize
44
+ # => http://api.rubyonrails.org/classes/ActiveModel/Callbacks.html
45
+ # => http://stackoverflow.com/a/17682228/1143732
46
+ def initialize attributes={}
47
+ super
48
+ run_callbacks :initialize do
49
+ # => Needed for after_initialize
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ ##################################
56
+ ##################################
57
+
58
+ ####################
59
+ # Table #
60
+ ####################
61
+
62
+ # Schema
63
+ ###################
64
+ # class_name @exception.class.name
65
+ # status ActionDispatch::ExceptionWrapper.new(@request.env, @exception).status_code
66
+ # message @exception.message
67
+ # trace @exception.backtrace.join("\n")
68
+ # target @request.url
69
+ # referer @request.referer
70
+ # params @request.params.inspect
71
+ # user_agent @request.user_agent
72
+ # created_at
73
+ # updated_at
74
+
75
+ # => Table is called "errors"
76
+ # => Dev needs to use migration to create db
77
+ if ExceptionHandler.config.try(:db)
78
+ def self.table_name
79
+ ExceptionHandler.config.db
80
+ end
81
+ end
82
+
83
+ ##################################
84
+ ##################################
85
+
86
+ ####################
87
+ # Options #
88
+ ####################
89
+
90
+ # => Email
91
+ # => after_initialize invoked after .new method called
92
+ # => Should have been after_create but user may not save
93
+ after_initialize -> (e) { ExceptionHandler::ExceptionMailer.new_exception(e).deliver }, if: :email? # => see bottom of file
94
+
95
+ # => Attributes
96
+ attr_accessor :request, :klass, :exception, :description
97
+ attr_accessor *ATTRS unless ExceptionHandler.config.try(:db)
98
+
99
+ # => Validations
100
+ validates :user_agent, format: { without: Regexp.new( BOTS.join("|"), Regexp::IGNORECASE ) }
101
+
102
+ ##################################
103
+ ##################################
104
+
105
+ ####################################
106
+ # Virtual
107
+ ####################################
108
+
109
+ # => Exception (virtual)
110
+ # => Basis on which all the class is built
111
+ def exception
112
+ request.env['action_dispatch.exception']
113
+ end
114
+
115
+ # => Klass
116
+ # => Used for validation (needs to be cleaned up in 0.7.0)
117
+ def klass
118
+ exception.class
119
+ end
120
+
121
+ # => Description
122
+ def description
123
+ I18n.with_options scope: [:exception_handler], message: message, status: status do |i18n|
124
+ i18n.t response, default: Rack::Utils::HTTP_STATUS_CODES[status]
125
+ end
126
+ end
127
+
128
+ ####################################
129
+ # Exception
130
+ ####################################
131
+
132
+ # => Class Name
133
+ def class_name
134
+ exception.class.name
135
+ end
136
+
137
+ # => Message
138
+ def message
139
+ exception ? exception.message : Rack::Utils::HTTP_STATUS_CODES[status]
140
+ end
141
+
142
+ # => Trace
143
+ def trace
144
+ exception.backtrace.join("\n")
145
+ end
146
+
147
+ ####################################
148
+ # Request
149
+ ####################################
150
+
151
+ # => Target URL
152
+ def target
153
+ request.url
154
+ end
155
+
156
+ # => Referrer URL
157
+ def referer
158
+ request.referer
159
+ end
160
+
161
+ # => Params
162
+ def params
163
+ request.params.inspect
164
+ end
165
+
166
+ # => User Agent
167
+ def user_agent
168
+ request.user_agent
169
+ end
170
+
171
+ ####################################
172
+ # Other
173
+ ####################################
174
+
175
+ # => Status code (404, 500 etc)
176
+ def status
177
+ exception ? ActionDispatch::ExceptionWrapper.new(request.env, exception).try(:status_code) : request.env["PATH_INFO"][1..-1].to_i
178
+ end
179
+
180
+ # => Server Response ("Not Found" etc)
181
+ def response
182
+ ActionDispatch::ExceptionWrapper.rescue_responses[class_name]
183
+ end
184
+
185
+ ##################################
186
+ ##################################
187
+
188
+ private
189
+
190
+ # => Email
191
+ # => should be on the same line as after_initialize but too long
192
+ def email?
193
+ ExceptionHandler.config.try(:email).try(:is_a?, String) && ExceptionHandler.config.options(status, :notification) != false
194
+ end
195
+
196
+ end
197
+ end
198
+
199
+ ############################################################
200
+ ############################################################
@@ -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.to_s.first == "5" && 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