exception_handler 0.7.5.15 → 0.8.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.coveralls.yml +1 -0
- data/.gitignore +51 -33
- data/.rspec +3 -4
- data/.slugignore +7 -7
- data/.travis.yml +13 -5
- data/Gemfile +16 -13
- data/README.md +643 -436
- data/Rakefile +7 -7
- data/app/assets/stylesheets/exception_handler.css.erb +23 -18
- data/app/assets/stylesheets/styles/_base.css.erb +28 -35
- data/app/assets/stylesheets/styles/_exception.css.erb +106 -105
- data/app/assets/stylesheets/styles/_footer.css.erb +24 -24
- data/app/assets/stylesheets/styles/_responsive.css +5 -5
- data/app/controllers/exception_handler/exceptions_controller.rb +66 -59
- data/app/mailers/exception_handler/exception_mailer.rb +17 -17
- data/app/models/exception_handler/exception.rb +200 -191
- data/app/views/exception_handler/exceptions/show.html.erb +3 -3
- data/app/views/exception_handler/mailers/layout.haml +8 -8
- data/app/views/exception_handler/mailers/layout.text.erb +1 -1
- data/app/views/exception_handler/mailers/new_exception.erb +4 -4
- data/app/views/layouts/exception.html.erb +32 -27
- data/app/views/layouts/mailer.html.erb +5 -0
- data/app/views/layouts/mailer.text.erb +1 -0
- data/config/locales/exception_handler.en.yml +28 -28
- data/config/routes.rb +42 -0
- data/db/migrate/000000_create_errors.rb +34 -34
- data/exception_handler.gemspec +63 -80
- data/lib/exception_handler.rb +56 -45
- data/lib/exception_handler/config.rb +185 -103
- data/lib/exception_handler/engine.rb +78 -60
- data/lib/exception_handler/version.rb +25 -0
- data/lib/generators/exception_handler/views_generator.rb +33 -33
- data/spec/controllers/controller_spec.rb +107 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/.ruby-version +1 -0
- data/spec/dummy/Rakefile +6 -6
- data/spec/dummy/app/assets/config/manifest.js +3 -4
- data/spec/dummy/app/assets/javascripts/application.js +15 -13
- data/spec/dummy/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -15
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -5
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -5
- data/spec/dummy/app/controllers/application_controller.rb +2 -5
- data/spec/dummy/app/helpers/application_helper.rb +2 -2
- data/spec/dummy/app/jobs/application_job.rb +2 -2
- data/spec/dummy/app/mailers/application_mailer.rb +4 -4
- data/spec/dummy/app/models/application_record.rb +3 -3
- data/spec/dummy/app/views/layouts/application.html.erb +15 -15
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -13
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -1
- data/spec/dummy/bin/bundle +3 -3
- data/spec/dummy/bin/rails +4 -4
- data/spec/dummy/bin/rake +4 -4
- data/spec/dummy/bin/setup +36 -34
- data/spec/dummy/bin/update +31 -29
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config.ru +5 -8
- data/spec/dummy/config/application.rb +18 -21
- data/spec/dummy/config/boot.rb +5 -5
- data/spec/dummy/config/cable.yml +10 -10
- data/spec/dummy/config/database.yml +25 -25
- data/spec/dummy/config/environment.rb +5 -5
- data/spec/dummy/config/environments/development.rb +61 -62
- data/spec/dummy/config/environments/production.rb +94 -87
- data/spec/dummy/config/environments/test.rb +46 -42
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -6
- data/spec/dummy/config/initializers/assets.rb +14 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -5
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
- data/spec/dummy/config/initializers/inflections.rb +16 -16
- data/spec/dummy/config/initializers/mime_types.rb +4 -4
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +33 -23
- data/spec/dummy/config/puma.rb +34 -47
- data/spec/dummy/config/routes.rb +3 -6
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +67 -67
- data/spec/dummy/public/422.html +67 -67
- data/spec/dummy/public/500.html +66 -66
- data/spec/dummy/spec/rails_helper.rb +57 -0
- data/spec/dummy/spec/spec_helper.rb +100 -0
- data/spec/dummy/storage/.keep +0 -0
- data/spec/features/asset_spec.rb +61 -0
- data/spec/features/config_spec.rb +51 -0
- data/spec/features/engine_spec.rb +180 -0
- data/spec/mailers/mailer_spec.rb +26 -0
- data/spec/models/model_spec.rb +26 -0
- data/spec/routing/routing_spec.rb +85 -0
- data/spec/spec_helper.rb +101 -55
- data/spec/views/views_spec.rb +29 -0
- metadata +47 -24
- data/.gitattributes +0 -1
- data/LICENSE.txt +0 -22
- data/app/assets/images/exception_handler/bg.jpg +0 -0
- data/app/assets/images/exception_handler/bg_overlay.png +0 -0
- data/spec/database.yml +0 -3
- data/spec/dummy/app/assets/javascripts/cable.coffee +0 -11
- data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +0 -6
- data/spec/dummy/config/initializers/callback_terminator.rb +0 -6
- data/spec/dummy/config/initializers/per_form_csrf_tokens.rb +0 -4
- data/spec/dummy/config/initializers/request_forgery_protection.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/exception_handler.rb +0 -22
- 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 "
|
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 =
|
19
|
-
|
20
|
-
|
21
|
-
# =>
|
22
|
-
if
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
include ActiveModel::
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# =>
|
44
|
-
# => http://
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
##################################
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
|
74
|
-
|
75
|
-
# =>
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
##################################
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
# =>
|
91
|
-
# =>
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
attr_accessor
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
validates :user_agent, format:
|
101
|
-
|
102
|
-
##################################
|
103
|
-
##################################
|
104
|
-
|
105
|
-
####################################
|
106
|
-
# Virtual
|
107
|
-
####################################
|
108
|
-
|
109
|
-
# =>
|
110
|
-
# =>
|
111
|
-
def
|
112
|
-
exception
|
113
|
-
end
|
114
|
-
|
115
|
-
# =>
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
##################################
|
186
|
-
|
187
|
-
|
188
|
-
|
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
|
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
|