exception_handler 0.7.5 → 0.8.0.1
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 -0
- data/.travis.yml +13 -5
- data/Gemfile +16 -13
- data/README.md +643 -443
- 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 -55
- 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 -29
- data/config/routes.rb +42 -0
- data/db/migrate/000000_create_errors.rb +34 -34
- data/exception_handler.gemspec +64 -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 +54 -28
- 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,103 +1,185 @@
|
|
1
|
-
###########################################
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
facebook:
|
51
|
-
twitter:
|
52
|
-
youtube:
|
53
|
-
linkedin:
|
54
|
-
fusion:
|
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
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
1
|
+
###########################################
|
2
|
+
###########################################
|
3
|
+
## _____ __ _ ##
|
4
|
+
## / __ \ / _(_) ##
|
5
|
+
## | / \/ ___ _ __ | |_ _ __ _ ##
|
6
|
+
## | | / _ \| '_ \| _| |/ _` | ##
|
7
|
+
## | \__/\ (_) | | | | | | | (_| | ##
|
8
|
+
## \____/\___/|_| |_|_| |_|\__, | ##
|
9
|
+
## __/ | ##
|
10
|
+
## |___/ ##
|
11
|
+
###########################################
|
12
|
+
###########################################
|
13
|
+
|
14
|
+
# Refs
|
15
|
+
# http://stackoverflow.com/questions/10584638/setting-up-configuration-settings-when-writing-a-gem
|
16
|
+
# http://robots.thoughtbot.com/mygem-configure-block
|
17
|
+
|
18
|
+
###########################################
|
19
|
+
###########################################
|
20
|
+
|
21
|
+
module ExceptionHandler
|
22
|
+
class Config
|
23
|
+
|
24
|
+
# => Instace Objects
|
25
|
+
# => ExceptionHandler.config.dev
|
26
|
+
# => ExceptionHandler.config.db
|
27
|
+
# => ExceptionHandler.config.email
|
28
|
+
# => ExceptionHandler.config.social
|
29
|
+
# => ExceptionHandler.config.layouts -> will need to be deprecated
|
30
|
+
# => ExceptionHandler.config.exceptions
|
31
|
+
# => ExceptionHandler.config.custom_exceptions
|
32
|
+
attr_accessor :dev, :db, :email, :social, :layouts, :exceptions, :custom_exceptions
|
33
|
+
|
34
|
+
###########################################
|
35
|
+
###########################################
|
36
|
+
###########################################
|
37
|
+
###########################################
|
38
|
+
|
39
|
+
# => Table Name
|
40
|
+
# => Has to be "errors" because "exceptions" is a reserved word
|
41
|
+
TABLE = :errors
|
42
|
+
|
43
|
+
###########################################
|
44
|
+
###########################################
|
45
|
+
|
46
|
+
# => Social URLs
|
47
|
+
# => Extracted from "social" block
|
48
|
+
SOCIAL =
|
49
|
+
ActiveSupport::HashWithIndifferentAccess.new({
|
50
|
+
facebook: "https://www.facebook.com",
|
51
|
+
twitter: "https://www.twitter.com",
|
52
|
+
youtube: "https://www.youtube.com/user",
|
53
|
+
linkedin: "https://www.linkedin.com/company",
|
54
|
+
fusion: "https://www.frontlinefusion.com"
|
55
|
+
})
|
56
|
+
|
57
|
+
###########################################
|
58
|
+
###########################################
|
59
|
+
|
60
|
+
# => Defaults
|
61
|
+
# => http://stackoverflow.com/a/8917301/1143732
|
62
|
+
DEFAULTS =
|
63
|
+
ActiveSupport::HashWithIndifferentAccess.new({
|
64
|
+
|
65
|
+
# => General options
|
66
|
+
dev: nil, # => defaults to "false" for dev mode
|
67
|
+
db: nil, # => defaults to :errors if true, else use "table_name" / :table_name
|
68
|
+
email: nil, # => requires string email and ActionMailer
|
69
|
+
|
70
|
+
# => Used in "exception" layout
|
71
|
+
social: {
|
72
|
+
facebook: nil,
|
73
|
+
twitter: nil,
|
74
|
+
youtube: nil,
|
75
|
+
linkedin: nil,
|
76
|
+
fusion: nil,
|
77
|
+
},
|
78
|
+
|
79
|
+
# => Defaults for exceptions. Override with specific status codes
|
80
|
+
# => Please note these are all STRINGS
|
81
|
+
exceptions: {
|
82
|
+
|
83
|
+
# => 4xx/5xx base standard
|
84
|
+
# => :all provide block customization (overrides 4xx/5xx)
|
85
|
+
# => specific provides individual (overrides all)
|
86
|
+
|
87
|
+
# => 4xx Errors (resource not found)
|
88
|
+
# => https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_errors
|
89
|
+
'4xx' => {
|
90
|
+
layout: nil
|
91
|
+
# notification: true #(this is for emails - it's true by default - only if you have email inputted)
|
92
|
+
# action: ____, (this is general)
|
93
|
+
# background: (can define custom background for exceptions layout if required)
|
94
|
+
},
|
95
|
+
|
96
|
+
# => 5xx Errors (server error)
|
97
|
+
# => https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_errors
|
98
|
+
'5xx' => {
|
99
|
+
layout: 'exception'
|
100
|
+
# notification: true (this is for emails - it's true by default - only if you have email inputted)
|
101
|
+
# action: _____, (this is general)
|
102
|
+
# background: (can define custom background for exceptions layout if required)
|
103
|
+
}
|
104
|
+
},
|
105
|
+
|
106
|
+
# Deprecated
|
107
|
+
#layouts: {
|
108
|
+
# => nil inherits from ApplicationController
|
109
|
+
# => 4xx errors should be nil
|
110
|
+
# => 5xx errors should be "exception" but can be nil if explicitly defined
|
111
|
+
#500 => 'exception',
|
112
|
+
#501 => 'exception',
|
113
|
+
#502 => 'exception',
|
114
|
+
#503 => 'exception',
|
115
|
+
#504 => 'exception',
|
116
|
+
#505 => 'exception',
|
117
|
+
#507 => 'exception',
|
118
|
+
#510 => 'exception'
|
119
|
+
#},
|
120
|
+
|
121
|
+
# => If you want to map your own classes to HTTP errors
|
122
|
+
# => use this...
|
123
|
+
custom_exceptions: {
|
124
|
+
#'ActionController::RoutingError' => :not_found # => example
|
125
|
+
}
|
126
|
+
|
127
|
+
})
|
128
|
+
|
129
|
+
###########################################
|
130
|
+
###########################################
|
131
|
+
|
132
|
+
# => Constructor
|
133
|
+
# => Merges DEFAULTS to values, creates instances vars (for attr_accessor)
|
134
|
+
def initialize values
|
135
|
+
|
136
|
+
# => Vars
|
137
|
+
DEFAULTS.deep_merge!(values || {}).each do |k,v|
|
138
|
+
instance_variable_set("@#{k}",v)
|
139
|
+
end
|
140
|
+
|
141
|
+
# => Validation
|
142
|
+
raise ExceptionHandler::Error, "Email Not Valid" if @email && !@email.nil? && !@email.is_a?(String)
|
143
|
+
raise ExceptionHandler::Error, "Migration Required → \"#{db}\" doesn't exist" if @db && !ActiveRecord::Base.connection.table_exists?(db) && (File.basename($0) != "rake" && !ARGV.include?("db:migrate"))
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
###########################################
|
148
|
+
###########################################
|
149
|
+
|
150
|
+
# => DB
|
151
|
+
# => If config db = "true", use TABLE constant
|
152
|
+
def db
|
153
|
+
@db == true ? TABLE : @db.try(:parameterize, separator: "_")
|
154
|
+
end
|
155
|
+
|
156
|
+
###########################################
|
157
|
+
###########################################
|
158
|
+
|
159
|
+
# => Options
|
160
|
+
# => Requires argument
|
161
|
+
def options status, pluck=nil
|
162
|
+
|
163
|
+
# => Structure from old + new setup
|
164
|
+
# => 1. layouts => [500, '500']
|
165
|
+
# => 2. exceptions => [500, '500' 'all', '4xx'/'5xx']
|
166
|
+
{ layouts: [status, status.to_s], # old + new
|
167
|
+
exceptions: [status, status.to_s, 'all', status.to_s.first + 'xx'] }.each do |key,array|
|
168
|
+
|
169
|
+
# => Array
|
170
|
+
# => https://stackoverflow.com/a/26877095/1143732
|
171
|
+
array.each do |specific|
|
172
|
+
item = self.send(key).try(:[], specific)
|
173
|
+
return (item.is_a?(Hash) ? ActiveSupport::HashWithIndifferentAccess.new(item)[pluck.try(:to_sym)] : item) if item.present? || (self.send(key).try(:has_key?, specific) && item.nil?) #if result exists and it has a value (including nil)
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
###########################################
|
180
|
+
###########################################
|
181
|
+
###########################################
|
182
|
+
###########################################
|
183
|
+
|
184
|
+
end
|
185
|
+
end
|
@@ -1,60 +1,78 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
# =>
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
1
|
+
###########################################
|
2
|
+
###########################################
|
3
|
+
## _____ _ ##
|
4
|
+
## | ___| (_) ##
|
5
|
+
## | |__ _ __ __ _ _ _ __ ___ ##
|
6
|
+
## | __| '_ \ / _` | | '_ \ / _ \ ##
|
7
|
+
## | |__| | | | (_| | | | | | __/ ##
|
8
|
+
## \____/_| |_|\__, |_|_| |_|\___| ##
|
9
|
+
## __/ | ##
|
10
|
+
## |___/ ##
|
11
|
+
###########################################
|
12
|
+
###########################################
|
13
|
+
|
14
|
+
module ExceptionHandler
|
15
|
+
class Engine < Rails::Engine
|
16
|
+
|
17
|
+
# => Rails default MIME types:
|
18
|
+
# => http://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to#14-Rails-defined-Mime-Types
|
19
|
+
|
20
|
+
#########################################################
|
21
|
+
#########################################################
|
22
|
+
|
23
|
+
# => Wraps helpers in ExceptionHandler module
|
24
|
+
# => http://guides.rubyonrails.org/engines.html#inside-an-engine
|
25
|
+
# => http://stackoverflow.com/questions/31877839/accessing-helpers-from-the-parent-app-in-an-isolated-rails-engine
|
26
|
+
isolate_namespace ExceptionHandler
|
27
|
+
|
28
|
+
# => Tests
|
29
|
+
config.generators do |g|
|
30
|
+
g.test_framework :rspec
|
31
|
+
end
|
32
|
+
|
33
|
+
# => Assets
|
34
|
+
# => For Sprockets 4, had to include link_tree in exception_handler.css
|
35
|
+
config.assets.precompile << "exception_handler.css"
|
36
|
+
|
37
|
+
#########################################################
|
38
|
+
#########################################################
|
39
|
+
|
40
|
+
# => Config
|
41
|
+
# => Builds lib/exception_handler/config.rb
|
42
|
+
# => config.before_initialize do |app| => Needs to be fixed for ActiveRecord::Base
|
43
|
+
# => to support later version of config, "with_indifferent_access" used in config.rb
|
44
|
+
initializer :exception_handler_config, before: "better_errors.configure_rails_initialization" do |app|
|
45
|
+
ExceptionHandler.config ||= ExceptionHandler::Config.new config.try(:exception_handler)
|
46
|
+
end
|
47
|
+
|
48
|
+
#########################################################
|
49
|
+
#########################################################
|
50
|
+
|
51
|
+
# => Middleware
|
52
|
+
# => This should be config.before_initialize but because ActiveRecord is not initialized, cannot check for table
|
53
|
+
initializer :exception_handler, before: "better_errors.configure_rails_initialization" do |app|
|
54
|
+
app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionsController.action(:show).call(env) }
|
55
|
+
app.config.consider_all_requests_local = !ExceptionHandler.config.try(:dev) if Rails.env.development? || Rails.env.test?
|
56
|
+
end
|
57
|
+
|
58
|
+
# => Custom Exceptions
|
59
|
+
# => This just mimicks standard Rails behaviour
|
60
|
+
# => Look for "config.action_dispatch.rescue_responses" for more info)
|
61
|
+
initializer :exception_handler_custom_exceptions do |app|
|
62
|
+
app.config.action_dispatch.rescue_responses.merge! ExceptionHandler.config.custom_exceptions if ExceptionHandler.config.custom_exceptions
|
63
|
+
end
|
64
|
+
|
65
|
+
# => Migrations
|
66
|
+
# => This has to be kept in an initializer (to access app)
|
67
|
+
# => https://blog.pivotal.io/labs/labs/leave-your-migrations-in-your-rails-engines
|
68
|
+
initializer :migration_paths do |app|
|
69
|
+
config.paths["db/migrate"].expanded.each do |expanded_path|
|
70
|
+
app.config.paths["db/migrate"] << expanded_path if ExceptionHandler.config.try(:db)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
#########################################################
|
75
|
+
#########################################################
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
###########################################
|
2
|
+
###########################################
|
3
|
+
## _ _ _ ##
|
4
|
+
## | | | | (_) ##
|
5
|
+
## | | | | ___ _ __ ___ _ ___ _ __ ##
|
6
|
+
## | | | |/ _ \ '__/ __| |/ _ \| '_ \ ##
|
7
|
+
## \ \_/ / __/ | \__ \ | (_) | | | | ##
|
8
|
+
## \___/ \___|_| |___/_|\___/|_| |_| ##
|
9
|
+
## ##
|
10
|
+
###########################################
|
11
|
+
###########################################
|
12
|
+
|
13
|
+
module ExceptionHandler
|
14
|
+
module VERSION
|
15
|
+
MAJOR = 0
|
16
|
+
MINOR = 8
|
17
|
+
TINY = 0
|
18
|
+
PRE = 1 # "alpha"
|
19
|
+
|
20
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
###########################################
|
25
|
+
###########################################
|