exception_handler 0.4.7 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.rspec +3 -1
- data/Gemfile +1 -1
- data/README.md +241 -92
- data/app/controllers/exception_handler/exception_controller.rb +13 -44
- data/app/helpers/exception_handler/application_helper.rb +47 -23
- data/app/models/exception_handler/error.rb +10 -9
- data/app/services/exception_handler/exception.rb +34 -0
- data/app/views/exception_handler/exception/show.html.erb +9 -6
- data/app/views/layouts/exception.html.erb +3 -3
- data/config/locales/en.yml +9 -0
- data/exception_handler.gemspec +16 -6
- data/lib/exception_handler.rb +67 -32
- data/lib/exception_handler/config.rb +49 -46
- data/lib/exception_handler/parse.rb +17 -17
- data/lib/exception_handler/parser/data.rb +57 -51
- data/lib/exception_handler/parser/ignore.rb +23 -23
- data/lib/exception_handler/version.rb +1 -1
- data/lib/generators/exception_handler/migration_generator.rb +17 -17
- data/lib/generators/exception_handler/views_generator.rb +27 -27
- data/spec/database.yml +3 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +4 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/cable.coffee +11 -0
- data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +5 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +5 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +34 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/config.ru +8 -0
- data/spec/dummy/config/application.rb +21 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +62 -0
- data/spec/dummy/config/environments/production.rb +87 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +6 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/callback_terminator.rb +6 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/per_form_csrf_tokens.rb +4 -0
- data/spec/dummy/config/initializers/request_forgery_protection.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/puma.rb +47 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/exception_handler.rb +22 -0
- data/spec/helpers/exception_handler/application_helper_spec.rb +42 -0
- data/spec/spec_helper.rb +28 -9
- metadata +102 -39
- data/readme/400.jpg +0 -0
- data/readme/500.jpg +0 -0
- data/readme/application_controller.jpg +0 -0
- data/readme/config.jpg +0 -0
- data/readme/db.jpg +0 -0
- data/readme/db_edit.jpg +0 -0
- data/readme/dev.jpg +0 -0
- data/readme/exception_controller.jpg +0 -0
- data/readme/exceptions_app.png +0 -0
- data/readme/layout.jpg +0 -0
- data/readme/parser.jpg +0 -0
- data/readme/rubygems.jpg +0 -0
- data/readme/source/screen.psd +0 -0
- data/readme/source/subtitle.psd +0 -0
- data/readme/source/title.psd +0 -0
- data/readme/subtitle.jpg +0 -0
- data/readme/title.jpg +0 -0
- data/readme/titles/bugs.png +0 -0
- data/readme/titles/contents.png +0 -0
- data/readme/titles/contribution.png +0 -0
- data/readme/titles/custom_error_pages.png +0 -0
- data/readme/titles/support.png +0 -0
- data/readme/titles/testing.png +0 -0
- data/readme/titles/title.psd +0 -0
- data/readme/view.jpg +0 -0
@@ -7,59 +7,62 @@
|
|
7
7
|
###########################################
|
8
8
|
|
9
9
|
module ExceptionHandler
|
10
|
-
|
10
|
+
class Config
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
#Instace Objects
|
13
|
+
attr_accessor :dev, :db, :email, :social, :layouts
|
14
14
|
|
15
|
-
|
15
|
+
###########################################
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
#Init
|
18
|
+
def initialize values=nil
|
19
|
+
defaults = values.present? ? Config::DEFAULTS.deep_merge!(values) : Config::DEFAULTS
|
20
|
+
defaults.each do |k,v|
|
21
|
+
instance_variable_set("@#{k}",v) #-> http://apidock.com/ruby/Object/instance_variable_set
|
22
|
+
end
|
23
|
+
end
|
24
24
|
|
25
|
-
|
25
|
+
# INSTANCE METHODS #
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
#DB
|
28
|
+
def db
|
29
|
+
@db == true ? Config::TABLE_NAME : @db
|
30
|
+
end
|
31
31
|
|
32
|
-
|
32
|
+
###########################################
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
#Default Table Name
|
35
|
+
# Has to be "errors" because "exceptions" is a reserved word
|
36
|
+
TABLE_NAME = :errors
|
37
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
|
-
|
38
|
+
# Defaults
|
39
|
+
# http://stackoverflow.com/a/8917301/1143732
|
40
|
+
DEFAULTS = {
|
41
|
+
dev: false, #-> defaults to "false" for dev mode
|
42
|
+
db: false, #-> defaults to :errors if true, else use "table_name" / :table_name
|
43
|
+
email: false, #-> need to integrate
|
44
|
+
social: {
|
45
|
+
:facebook => 'frontline.utilities',
|
46
|
+
:twitter => 'frontlineutils',
|
47
|
+
:youtube => 'frontlineutils',
|
48
|
+
:linkedin => 'frontline-utilities',
|
49
|
+
:fusion => 'frontlineutils',
|
50
|
+
:url => {
|
51
|
+
:facebook => 'https://facebook.com',
|
52
|
+
:twitter => 'http://twitter.com',
|
53
|
+
:youtube => 'https://youtube.com/user',
|
54
|
+
:linkedin => 'https://linkedin.com/company',
|
55
|
+
:fusion => 'https://frontlinefusion.com',
|
56
|
+
},
|
57
|
+
},
|
58
|
+
layouts: {
|
59
|
+
'404' => nil, #-> 404 Callback (needs improving big time) Use the following: '404' => <<-EOF redirect_to root_url, notice: "Hello" EOF
|
60
|
+
'400' => nil, #-> layout for 400 error code (404 should only be used as response)
|
61
|
+
'500' => 'exception'
|
62
|
+
},
|
63
|
+
}
|
63
64
|
|
64
|
-
|
65
|
+
###########################################
|
66
|
+
|
67
|
+
end
|
65
68
|
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
module ExceptionHandler
|
2
|
-
|
2
|
+
class Parse
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
# Init
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
#Exception
|
10
|
+
def call(env)
|
11
|
+
@app.call(env)
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
rescue Exception => exception
|
14
|
+
request = ActionDispatch::Request.new(env)
|
15
|
+
controller = request.env['action_controller.instance']
|
16
|
+
ignore = ExceptionHandler::Parser::Ignore.new(exception, request).match?
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
ExceptionHandler::Parser::Data.create exception, request, controller unless ignore
|
19
|
+
raise exception
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,53 +1,59 @@
|
|
1
1
|
module ExceptionHandler
|
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
|
-
|
2
|
+
module Parser
|
3
|
+
class Data
|
4
|
+
|
5
|
+
# Data
|
6
|
+
attr_reader :exception, :request, :controller, :user
|
7
|
+
|
8
|
+
#Create
|
9
|
+
class << self
|
10
|
+
def create exception, request, controller
|
11
|
+
|
12
|
+
@exception = exception
|
13
|
+
@request = request
|
14
|
+
@controller = controller
|
15
|
+
|
16
|
+
#http://blog.habanerohq.com/post/16800611137/selectively-silence-activerecord-logging
|
17
|
+
message = ""
|
18
|
+
Rails.logger.silence do #-> stops Error.create from showing output
|
19
|
+
ExceptionHandler::Error.create info do |error|
|
20
|
+
message += "\n======================\n"
|
21
|
+
message += "#{error.class_name}:\n"
|
22
|
+
message += "\n#{error.message}\n"
|
23
|
+
message += Rails.backtrace_cleaner.clean(error.trace.split("\n")).join("\n")
|
24
|
+
message += "\n======================\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
Rails.logger.fatal message unless message.blank?
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
#User
|
35
|
+
def user
|
36
|
+
@controller.send(:current_user) if @controller.respond_to?(:current_user)
|
37
|
+
end
|
38
|
+
|
39
|
+
#Info
|
40
|
+
def info
|
41
|
+
info = {
|
42
|
+
class_name: @exception.class.to_s,
|
43
|
+
message: @exception.message.to_s,
|
44
|
+
trace: @exception.backtrace.join("\n"),
|
45
|
+
target_url: @request.url,
|
46
|
+
referer_url: @request.referer,
|
47
|
+
params: @request.params.inspect,
|
48
|
+
user_agent: @request.user_agent
|
49
|
+
}
|
50
|
+
if @user && @user.respond_to(:id)
|
51
|
+
info[:usable_type] = @user.model_name.human
|
52
|
+
info[:usable_id] = @user.id
|
53
|
+
end
|
54
|
+
info
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
53
59
|
end
|
@@ -1,32 +1,32 @@
|
|
1
1
|
module ExceptionHandler
|
2
|
-
|
3
|
-
|
2
|
+
module Parser
|
3
|
+
class Ignore
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
#Init
|
6
|
+
def initialize(exception, request)
|
7
|
+
@exception, @request = exception, request
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
#Matches?
|
11
|
+
def match?
|
12
|
+
return true if errors.include?(@exception.class) && @request.referer.blank?
|
13
|
+
return true if @request.user_agent =~ bots
|
14
|
+
end
|
15
15
|
|
16
|
-
|
16
|
+
private
|
17
17
|
|
18
|
-
|
18
|
+
#Has to be instance vars for env to handle ActionController::RoutingError constant etc
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
#Errors
|
21
|
+
def errors #-> http://ruby-doc.org/core-2.2.0/Array.html#class-Array-label-Creating+Arrays
|
22
|
+
[ActionController::RoutingError, AbstractController::ActionNotFound, ActiveRecord::RecordNotFound]
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
#Bots
|
26
|
+
def bots
|
27
|
+
Regexp.new %w(Baidu Gigabot Googlebot libwww-per lwp-trivial msnbot SiteUptime Slurp Wordpress ZIBB ZyBorg Yandex Jyxobot Huaweisymantecspider ApptusBot).join("|"), Regexp::IGNORECASE
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
end
|
31
|
+
end
|
32
32
|
end
|
@@ -10,28 +10,28 @@ require 'rails/generators/active_record'
|
|
10
10
|
module ExceptionHandler
|
11
11
|
class MigrationGenerator < ActiveRecord::Generators::Base
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
#Name - from http://old.thoughtsincomputation.com/posts/cgfr3-part-3-adding-a-generator
|
14
|
+
argument :name, default: "migration"
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
#Source of Migrations
|
17
|
+
source_root File.expand_path("../../templates", __FILE__)
|
18
18
|
|
19
|
-
|
19
|
+
###########################################
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
#Table Name - false = off, true = errors, value = value
|
22
|
+
#Always outputs string for some reason...
|
23
|
+
def table_name
|
24
|
+
ExceptionHandler.config.db
|
25
|
+
end
|
26
26
|
|
27
|
-
|
27
|
+
###########################################
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
#Create
|
30
|
+
def create_errors_migration
|
31
|
+
migration_template "migration.rb.erb", "db/migrate/create_errors.rb"
|
32
|
+
end
|
33
33
|
|
34
|
-
|
34
|
+
###########################################
|
35
35
|
|
36
|
-
|
36
|
+
end
|
37
37
|
end
|
@@ -1,42 +1,42 @@
|
|
1
1
|
module ExceptionHandler
|
2
|
-
|
2
|
+
class ViewsGenerator < Rails::Generators::Base
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
#Views
|
5
|
+
@@views = %w(views controllers helpers models assets)
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
#Options
|
8
|
+
class_option :files, aliases: "-v", default: @@views, type: :array, desc: "Select file types (views, models, controllers, assets)"
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
#Needed to reference files
|
11
|
+
source_root File.expand_path("../../../../app", __FILE__)
|
12
12
|
|
13
|
-
|
13
|
+
###########################################
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
#Files
|
16
|
+
def create_files
|
17
|
+
generate_files options.files
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
###########################################
|
21
21
|
|
22
|
-
|
22
|
+
protected
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
#File Generator
|
25
|
+
def generate_files args
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
#Valid?
|
28
|
+
return raise args.inspect unless args.nil? || (args-@@views).empty?
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
#Types
|
31
|
+
for arg in args do
|
32
|
+
directory arg, "app/#{arg}"
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
#Success
|
36
|
+
puts "Files transferred successfully"
|
37
|
+
end
|
38
38
|
|
39
|
-
|
39
|
+
###########################################
|
40
40
|
|
41
|
-
|
41
|
+
end
|
42
42
|
end
|
data/spec/database.yml
ADDED
data/spec/dummy/Rakefile
ADDED