exception_handler 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +33 -33
- data/.rspec +3 -3
- data/.travis.yml +5 -5
- data/Gemfile +13 -13
- data/LICENSE.txt +22 -22
- data/README.md +349 -341
- data/Rakefile +7 -7
- data/app/assets/images/{favicon.ico → exception_handler.ico} +0 -0
- data/app/assets/images/exception_handler/alert.jpg +0 -0
- data/app/assets/images/exception_handler/bg.jpg +0 -0
- data/app/assets/images/exception_handler/favicon.ico +0 -0
- data/app/assets/images/exception_handler/icon.png +0 -0
- data/app/assets/stylesheets/exception_handler.css.erb +8 -8
- data/app/assets/stylesheets/styles/_base.css.erb +35 -34
- data/app/assets/stylesheets/styles/_exception.css.erb +105 -103
- data/app/assets/stylesheets/styles/_footer.css.erb +24 -27
- data/app/assets/stylesheets/styles/_responsive.css +5 -5
- data/app/controllers/exception_handler/exception_controller.rb +45 -38
- data/app/mailers/exception_handler/exception_mailer.rb +16 -16
- data/app/models/exception_handler/exception.rb +191 -191
- data/app/views/exception_handler/exception/show.html.erb +1 -1
- data/app/views/exception_handler/mailers/new_exception.erb +4 -4
- data/app/views/layouts/exception.html.erb +27 -21
- data/config/locales/exception_handler.en.yml +13 -13
- data/exception_handler.gemspec +80 -84
- data/lib/exception_handler.rb +32 -29
- data/lib/exception_handler/config.rb +80 -66
- data/lib/exception_handler/engine.rb +44 -36
- data/lib/generators/exception_handler/migration_generator.rb +55 -55
- data/lib/generators/exception_handler/views_generator.rb +42 -42
- data/lib/generators/templates/migration.rb.erb +16 -16
- data/spec/database.yml +2 -2
- data/spec/dummy/Rakefile +6 -6
- data/spec/dummy/app/assets/config/manifest.js +4 -4
- data/spec/dummy/app/assets/javascripts/application.js +13 -13
- data/spec/dummy/app/assets/javascripts/cable.coffee +11 -11
- data/spec/dummy/app/assets/stylesheets/application.css +15 -15
- data/spec/dummy/app/channels/application_cable/channel.rb +5 -5
- data/spec/dummy/app/channels/application_cable/connection.rb +5 -5
- data/spec/dummy/app/controllers/application_controller.rb +5 -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 +34 -34
- data/spec/dummy/bin/update +29 -29
- data/spec/dummy/config.ru +8 -8
- data/spec/dummy/config/application.rb +21 -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 +62 -62
- data/spec/dummy/config/environments/production.rb +87 -87
- data/spec/dummy/config/environments/test.rb +42 -42
- data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +6 -6
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -6
- data/spec/dummy/config/initializers/assets.rb +11 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
- data/spec/dummy/config/initializers/callback_terminator.rb +6 -6
- 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/per_form_csrf_tokens.rb +4 -4
- data/spec/dummy/config/initializers/request_forgery_protection.rb +4 -4
- data/spec/dummy/config/initializers/session_store.rb +3 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
- data/spec/dummy/config/locales/en.yml +23 -23
- data/spec/dummy/config/puma.rb +47 -47
- data/spec/dummy/config/routes.rb +6 -6
- data/spec/dummy/config/secrets.yml +22 -22
- 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/exception_handler.rb +21 -21
- data/spec/exception_handler/exception_controller_spec.rb +18 -0
- data/spec/spec_helper.rb +54 -54
- metadata +11 -8
@@ -1,13 +1,13 @@
|
|
1
|
-
##################################
|
2
|
-
##################################
|
3
|
-
# Have to use strings rather than integers
|
4
|
-
##################################
|
5
|
-
##################################
|
6
|
-
|
7
|
-
en:
|
8
|
-
exception:
|
9
|
-
not_found: "Page missing"
|
10
|
-
internal_server_error: "<strong
|
11
|
-
|
12
|
-
##################################
|
13
|
-
##################################
|
1
|
+
##################################
|
2
|
+
##################################
|
3
|
+
# Have to use strings rather than integers
|
4
|
+
##################################
|
5
|
+
##################################
|
6
|
+
|
7
|
+
en:
|
8
|
+
exception:
|
9
|
+
not_found: "Page missing"
|
10
|
+
internal_server_error: "<strong>%{status} Error</strong> %{message} <p>Return home</p>"
|
11
|
+
|
12
|
+
##################################
|
13
|
+
##################################
|
data/exception_handler.gemspec
CHANGED
@@ -1,84 +1,80 @@
|
|
1
|
-
# Dependencies
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
|
5
|
-
##############################################################
|
6
|
-
##############################################################
|
7
|
-
|
8
|
-
# => Version
|
9
|
-
# => https://github.com/rails/rails/blob/master/version.rb
|
10
|
-
module ExceptionHandler
|
11
|
-
module VERSION
|
12
|
-
MAJOR = 0
|
13
|
-
MINOR =
|
14
|
-
TINY =
|
15
|
-
PRE = nil # "alpha"
|
16
|
-
|
17
|
-
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
s.
|
36
|
-
s.
|
37
|
-
|
38
|
-
# =>
|
39
|
-
s.
|
40
|
-
s.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
s.
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
s.
|
55
|
-
s.
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
s.
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
s.
|
69
|
-
|
70
|
-
|
71
|
-
# =>
|
72
|
-
s.add_development_dependency "
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
##############################################################
|
82
|
-
##############################################################
|
83
|
-
|
84
|
-
end
|
1
|
+
# Dependencies
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
##############################################################
|
6
|
+
##############################################################
|
7
|
+
|
8
|
+
# => Version
|
9
|
+
# => https://github.com/rails/rails/blob/master/version.rb
|
10
|
+
module ExceptionHandler
|
11
|
+
module VERSION
|
12
|
+
MAJOR = 0
|
13
|
+
MINOR = 7
|
14
|
+
TINY = 0
|
15
|
+
PRE = nil # "alpha"
|
16
|
+
|
17
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
##############################################################
|
22
|
+
##############################################################
|
23
|
+
|
24
|
+
# => Gem
|
25
|
+
Gem::Specification.new do |s|
|
26
|
+
|
27
|
+
##############################################################
|
28
|
+
|
29
|
+
# => General
|
30
|
+
s.platform = Gem::Platform::RUBY
|
31
|
+
s.name = "exception_handler"
|
32
|
+
s.version = ExceptionHandler::VERSION::STRING
|
33
|
+
|
34
|
+
# => Author
|
35
|
+
s.authors = ["Richard Peck"]
|
36
|
+
s.email = ["rpeck@frontlineutilities.co.uk"]
|
37
|
+
|
38
|
+
# => Details
|
39
|
+
s.summary = %q{Rails gem to show custom error pages in production. Also logs errors in db & sends notification emails}
|
40
|
+
s.description = %q{Rails gem to create custom error pages. Captures exceptions using "exception_app" callback, routing to "Exception" controller, rendering the view as required.}
|
41
|
+
s.homepage = "http://github.com/richpeck/exception_handler"
|
42
|
+
|
43
|
+
# => License
|
44
|
+
s.license = "MIT"
|
45
|
+
|
46
|
+
##############################################################
|
47
|
+
|
48
|
+
# => Files
|
49
|
+
# => Remove "readme" dir from gem
|
50
|
+
s.files = `git ls-files -z`.split("\x0")
|
51
|
+
s.files.reject! { |fn| fn.include? "readme" } #-> https://github.com/gauntlt/gauntlt/blob/master/gauntlt.gemspec#L16
|
52
|
+
|
53
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
54
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/}) unless RUBY_VERSION >= "2.2.0" #-> deprecated in Ruby 2.2.0
|
55
|
+
s.require_paths = ["lib"]
|
56
|
+
|
57
|
+
##############################################################
|
58
|
+
|
59
|
+
# => Ruby
|
60
|
+
s.required_ruby_version = ">= 2.1.0"
|
61
|
+
|
62
|
+
# => Runtime
|
63
|
+
s.add_dependency "bundler", "~> 1.6"
|
64
|
+
s.add_dependency "rails", ">= 4.2.0"
|
65
|
+
s.add_dependency "responders"
|
66
|
+
|
67
|
+
# => Extras
|
68
|
+
s.add_development_dependency "autoprefixer-rails"
|
69
|
+
|
70
|
+
# => Dev
|
71
|
+
# => For testing etc
|
72
|
+
s.add_development_dependency "rake"
|
73
|
+
s.add_development_dependency "rspec"
|
74
|
+
s.add_development_dependency "rspec-rails"
|
75
|
+
s.add_development_dependency "sqlite3", ">= 1.3.10"
|
76
|
+
|
77
|
+
##############################################################
|
78
|
+
##############################################################
|
79
|
+
|
80
|
+
end
|
data/lib/exception_handler.rb
CHANGED
@@ -1,29 +1,32 @@
|
|
1
|
-
#########################################################
|
2
|
-
#########################################################
|
3
|
-
|
4
|
-
module ExceptionHandler
|
5
|
-
|
6
|
-
# => Table Prefix
|
7
|
-
# => Keeps Rails Engine from generating all table prefixes with the engines name
|
8
|
-
# => http://stackoverflow.com/questions/19435214/rails-mountable-engine-with-isolate-namespace-but-without-prefixed-namespace-on
|
9
|
-
def self.table_name_prefix
|
10
|
-
# => No prefix
|
11
|
-
end
|
12
|
-
|
13
|
-
# => Config
|
14
|
-
# => Invoke instance of config (ExceptionHandler.config)
|
15
|
-
mattr_accessor :config
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
#########################################################
|
20
|
-
#########################################################
|
21
|
-
|
22
|
-
# => Libs
|
23
|
-
# => http://stackoverflow.com/a/4528011/1143732
|
24
|
-
# => http://stackoverflow.com/a/21693468/1143732
|
25
|
-
# => https://github.com/jekyll/jekyll/blob/master/lib/jekyll.rb#L8
|
26
|
-
Dir.glob(File.join(File.dirname(__FILE__), 'exception_handler', '**/*.rb'), &method(:require))
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
#########################################################
|
2
|
+
#########################################################
|
3
|
+
|
4
|
+
module ExceptionHandler
|
5
|
+
|
6
|
+
# => Table Prefix
|
7
|
+
# => Keeps Rails Engine from generating all table prefixes with the engines name
|
8
|
+
# => http://stackoverflow.com/questions/19435214/rails-mountable-engine-with-isolate-namespace-but-without-prefixed-namespace-on
|
9
|
+
def self.table_name_prefix
|
10
|
+
# => No prefix
|
11
|
+
end
|
12
|
+
|
13
|
+
# => Config
|
14
|
+
# => Invoke instance of config (ExceptionHandler.config)
|
15
|
+
mattr_accessor :config
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
#########################################################
|
20
|
+
#########################################################
|
21
|
+
|
22
|
+
# => Libs
|
23
|
+
# => http://stackoverflow.com/a/4528011/1143732
|
24
|
+
# => http://stackoverflow.com/a/21693468/1143732
|
25
|
+
# => https://github.com/jekyll/jekyll/blob/master/lib/jekyll.rb#L8
|
26
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'exception_handler', '**/*.rb'), &method(:require))
|
27
|
+
|
28
|
+
# => External Dependencies
|
29
|
+
require 'responders'
|
30
|
+
|
31
|
+
#########################################################
|
32
|
+
#########################################################
|
@@ -1,66 +1,80 @@
|
|
1
|
-
###########################################
|
2
|
-
|
3
|
-
# Refs
|
4
|
-
# http://stackoverflow.com/questions/10584638/setting-up-configuration-settings-when-writing-a-gem
|
5
|
-
# http://robots.thoughtbot.com/mygem-configure-block
|
6
|
-
|
7
|
-
###########################################
|
8
|
-
|
9
|
-
module ExceptionHandler
|
10
|
-
class Config
|
11
|
-
|
12
|
-
#Instace Objects
|
13
|
-
attr_accessor :dev, :db, :email, :social, :layouts
|
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
|
-
},
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
1
|
+
###########################################
|
2
|
+
|
3
|
+
# Refs
|
4
|
+
# http://stackoverflow.com/questions/10584638/setting-up-configuration-settings-when-writing-a-gem
|
5
|
+
# http://robots.thoughtbot.com/mygem-configure-block
|
6
|
+
|
7
|
+
###########################################
|
8
|
+
|
9
|
+
module ExceptionHandler
|
10
|
+
class Config
|
11
|
+
|
12
|
+
#Instace Objects
|
13
|
+
attr_accessor :dev, :db, :email, :social, :layouts
|
14
|
+
|
15
|
+
###########################################
|
16
|
+
###########################################
|
17
|
+
|
18
|
+
# Table Name
|
19
|
+
# Has to be "errors" because "exceptions" is a reserved word
|
20
|
+
TABLE = :errors
|
21
|
+
|
22
|
+
# Social URLs
|
23
|
+
# Extracted from "social" block
|
24
|
+
SOCIAL = {
|
25
|
+
facebook: "https://facebook.com",
|
26
|
+
twitter: "http://twitter.com",
|
27
|
+
youtube: "https://youtube.com/user",
|
28
|
+
linkedin: "https://linkedin.com/company",
|
29
|
+
fusion: "http://frontlinefusion.com"
|
30
|
+
}
|
31
|
+
|
32
|
+
###########################################
|
33
|
+
###########################################
|
34
|
+
|
35
|
+
# Defaults
|
36
|
+
# http://stackoverflow.com/a/8917301/1143732
|
37
|
+
DEFAULTS = {
|
38
|
+
dev: false, #-> defaults to "false" for dev mode
|
39
|
+
db: false, #-> defaults to :errors if true, else use "table_name" / :table_name
|
40
|
+
email: false, #-> requires string email and ActionMailer
|
41
|
+
social: {
|
42
|
+
facebook: nil,
|
43
|
+
twitter: nil,
|
44
|
+
youtube: nil,
|
45
|
+
linkedin: nil,
|
46
|
+
fusion: nil,
|
47
|
+
},
|
48
|
+
layouts: {
|
49
|
+
"400" => nil, # => inherits from "ApplicationController" layout
|
50
|
+
"500" => "exception"
|
51
|
+
},
|
52
|
+
}
|
53
|
+
|
54
|
+
###########################################
|
55
|
+
###########################################
|
56
|
+
|
57
|
+
#Init
|
58
|
+
def initialize values
|
59
|
+
# => Vars
|
60
|
+
DEFAULTS.deep_merge!(values || {}).each do |k,v|
|
61
|
+
instance_variable_set("@#{k}",v)
|
62
|
+
end
|
63
|
+
|
64
|
+
# => Errors
|
65
|
+
raise(Exception, "ExceptionHandler :: Valid Email Required") if @email && !@email.is_a?(String)
|
66
|
+
#raise(Exception, "ExceptionHandler :: Migration Required → Table \"#{db}\" doesn't exist") if @db && !ActiveRecord::Base.connection.table_exists?(db)
|
67
|
+
end
|
68
|
+
|
69
|
+
###########################################
|
70
|
+
###########################################
|
71
|
+
|
72
|
+
def db
|
73
|
+
@db == true ? TABLE : @db
|
74
|
+
end
|
75
|
+
|
76
|
+
###########################################
|
77
|
+
###########################################
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -1,36 +1,44 @@
|
|
1
|
-
module ExceptionHandler
|
2
|
-
class Engine < Rails::Engine
|
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
|
-
|
1
|
+
module ExceptionHandler
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
|
4
|
+
# => Rails default MIME types:
|
5
|
+
# => http://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to#14-Rails-defined-Mime-Types
|
6
|
+
|
7
|
+
#########################################################
|
8
|
+
#########################################################
|
9
|
+
|
10
|
+
# => Wraps helpers in ExceptionHandler module
|
11
|
+
# => http://guides.rubyonrails.org/engines.html#inside-an-engine
|
12
|
+
# => http://stackoverflow.com/questions/31877839/accessing-helpers-from-the-parent-app-in-an-isolated-rails-engine
|
13
|
+
isolate_namespace ExceptionHandler
|
14
|
+
|
15
|
+
# => Tests
|
16
|
+
config.generators do |g|
|
17
|
+
g.test_framework :rspec
|
18
|
+
end
|
19
|
+
|
20
|
+
# => Assets
|
21
|
+
# => For Sprockets 4, had to include link_tree in exception_handler.css
|
22
|
+
config.assets.precompile << %w(exception_handler.css)
|
23
|
+
|
24
|
+
#########################################################
|
25
|
+
#########################################################
|
26
|
+
|
27
|
+
# => Hooks
|
28
|
+
# => This should be config.before_initialize but because ActiveRecord is not initialized, cannot check for table
|
29
|
+
initializer :exception_handler, before: "better_errors.configure_rails_initialization" do |app|
|
30
|
+
|
31
|
+
# => Vars
|
32
|
+
ExceptionHandler.config ||= ExceptionHandler::Config.new config.try(:exception_handler)
|
33
|
+
|
34
|
+
# => Middleware
|
35
|
+
app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionController.action(:show).call(env) }
|
36
|
+
app.config.consider_all_requests_local = !ExceptionHandler.config.try(:dev) if Rails.env.development?
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
#########################################################
|
41
|
+
#########################################################
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|