exception_handler 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +4 -4
- data/Gemfile +1 -3
- data/README.md +111 -98
- data/app/assets/images/exception_handler/connect/facebook.png +0 -0
- data/app/assets/images/exception_handler/connect/fusion.png +0 -0
- data/app/assets/images/exception_handler/connect/linkedin.png +0 -0
- data/app/assets/images/exception_handler/connect/twitter.png +0 -0
- data/app/assets/images/exception_handler/connect/youtube.png +0 -0
- data/app/assets/images/exception_handler/noise.png +0 -0
- data/app/assets/images/favicon.ico +0 -0
- data/app/assets/stylesheets/exception_handler.css.erb +18 -0
- data/app/assets/stylesheets/styles/_base.css.erb +34 -0
- data/app/assets/stylesheets/styles/_exception.css.erb +105 -0
- data/app/assets/stylesheets/styles/_footer.css.erb +27 -0
- data/app/assets/stylesheets/styles/_responsive.css +5 -0
- data/app/controllers/exception_handler/exception_controller.rb +28 -33
- data/app/mailers/exception_handler/exception_mailer.rb +17 -0
- data/app/models/exception_handler/exception.rb +191 -0
- data/app/views/exception_handler/exception/show.html.erb +3 -32
- data/app/views/exception_handler/mailers/layout.haml +8 -0
- data/app/views/exception_handler/mailers/layout.text.erb +1 -0
- data/app/views/exception_handler/mailers/new_exception.erb +4 -0
- data/app/views/layouts/exception.html.erb +15 -23
- data/config/locales/exception_handler.en.yml +13 -0
- data/exception_handler.gemspec +61 -16
- data/lib/exception_handler.rb +20 -79
- data/lib/exception_handler/config.rb +20 -22
- data/lib/exception_handler/engine.rb +36 -0
- data/lib/generators/exception_handler/migration_generator.rb +28 -10
- data/lib/generators/exception_handler/views_generator.rb +5 -5
- data/lib/generators/templates/migration.rb.erb +12 -11
- metadata +41 -64
- data/app/assets/images/exception_handler/close.png +0 -0
- data/app/assets/images/exception_handler/home.png +0 -0
- data/app/assets/stylesheets/exception_handler/error.css.erb +0 -309
- data/app/helpers/exception_handler/application_helper.rb +0 -56
- data/app/models/exception_handler/error.rb +0 -14
- data/app/services/exception_handler/exception.rb +0 -34
- data/config/locales/en.yml +0 -9
- data/lib/exception_handler/parse.rb +0 -23
- data/lib/exception_handler/parser/data.rb +0 -59
- data/lib/exception_handler/parser/ignore.rb +0 -32
- data/lib/exception_handler/version.rb +0 -3
- data/post_install_message.md +0 -53
- data/spec/helpers/exception_handler/application_helper_spec.rb +0 -42
@@ -1,56 +0,0 @@
|
|
1
|
-
module ExceptionHandler
|
2
|
-
module ApplicationHelper
|
3
|
-
|
4
|
-
##################
|
5
|
-
|
6
|
-
#Refs
|
7
|
-
#http://stackoverflow.com/a/5795683/1143732
|
8
|
-
#http://stackoverflow.com/questions/8028021/helpers-in-rails-engine
|
9
|
-
#ActiveSupport.on_load( :action_view ){ include ExceptionHandler::ViewHelpers }
|
10
|
-
|
11
|
-
##################
|
12
|
-
|
13
|
-
#App (Application name)
|
14
|
-
def app
|
15
|
-
Rails.application.class.parent_name
|
16
|
-
end
|
17
|
-
|
18
|
-
#Details
|
19
|
-
def details
|
20
|
-
@details ||= {}.tap do |h|
|
21
|
-
I18n.with_options scope: [:exception, :show, @exception.response], message: @exception.message do |i18n|
|
22
|
-
h[:name] = i18n.t "#{@exception.class.name.underscore}.title", default: i18n.t(:title, default: @exception.class.name)
|
23
|
-
h[:description] = i18n.t "#{@exception.class.name.underscore}.description", default: i18n.t(:description, default: @exception.message)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
#Social
|
29
|
-
def social *services
|
30
|
-
output = []
|
31
|
-
# options = args.extract_options! http://simonecarletti.com/blog/2009/09/inside-ruby-on-rails-extract_options-from-arrays/ - args for hash
|
32
|
-
|
33
|
-
services = ExceptionHandler.config.social unless services.any? #-> http://api.rubyonrails.org/classes/Hash.html#method-i-compact
|
34
|
-
services.except(:url).compact.each do |service,username| #-> except http://stackoverflow.com/a/11105831/1143732
|
35
|
-
output.push link_to(image_tag("exception_handler/connect/#{service}.png", title: "Find us on " + service.to_s.titleize), link(service), target: :blank, class: service.to_s)
|
36
|
-
end
|
37
|
-
|
38
|
-
output.join("").html_safe #-> ruby returns last line
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
##################
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def link service #-> bloated way to allow single references in config
|
47
|
-
url = []
|
48
|
-
url.push ExceptionHandler.config.social[:url][service]
|
49
|
-
url.push ExceptionHandler.config.social[service]
|
50
|
-
url.join("/")
|
51
|
-
end
|
52
|
-
|
53
|
-
##################
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module ExceptionHandler
|
2
|
-
class Error < ActiveRecord::Base
|
3
|
-
|
4
|
-
#Table is called "errors"
|
5
|
-
#Dev needs to use migration to create db
|
6
|
-
def self.table_name
|
7
|
-
ExceptionHandler.config.db
|
8
|
-
end
|
9
|
-
|
10
|
-
#Associations
|
11
|
-
belongs_to :usable, polymorphic: true
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module ExceptionHandler
|
2
|
-
class Exception #-> https://www.netguru.co/blog/service-objects-in-rails-will-help
|
3
|
-
attr_reader :exception, :request, :class, :message
|
4
|
-
|
5
|
-
######################
|
6
|
-
|
7
|
-
def initialize request
|
8
|
-
@request = request
|
9
|
-
@exception = request.env['action_dispatch.exception']
|
10
|
-
|
11
|
-
@class = @exception.class
|
12
|
-
@message = @exception.message
|
13
|
-
end
|
14
|
-
|
15
|
-
######################
|
16
|
-
|
17
|
-
# Status code (404, 500 etc)
|
18
|
-
def code
|
19
|
-
ActionDispatch::ExceptionWrapper.new(@request.env, @exception).status_code
|
20
|
-
end
|
21
|
-
|
22
|
-
# Server Response ("Not Found" etc)
|
23
|
-
def response
|
24
|
-
ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]
|
25
|
-
end
|
26
|
-
|
27
|
-
######################
|
28
|
-
|
29
|
-
alias_method :status, :code #-> http://stackoverflow.com/a/11848832/1143732 (has to be below methods)
|
30
|
-
|
31
|
-
######################
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
data/config/locales/en.yml
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module ExceptionHandler
|
2
|
-
class Parse
|
3
|
-
|
4
|
-
# Init
|
5
|
-
def initialize(app)
|
6
|
-
@app = app
|
7
|
-
end
|
8
|
-
|
9
|
-
#Exception
|
10
|
-
def call(env)
|
11
|
-
@app.call(env)
|
12
|
-
|
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
|
-
|
18
|
-
ExceptionHandler::Parser::Data.create exception, request, controller unless ignore
|
19
|
-
raise exception
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module ExceptionHandler
|
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
|
59
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module ExceptionHandler
|
2
|
-
module Parser
|
3
|
-
class Ignore
|
4
|
-
|
5
|
-
#Init
|
6
|
-
def initialize(exception, request)
|
7
|
-
@exception, @request = exception, request
|
8
|
-
end
|
9
|
-
|
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
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
#Has to be instance vars for env to handle ActionController::RoutingError constant etc
|
19
|
-
|
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
|
-
|
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
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/post_install_message.md
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
########################################################################################
|
2
|
-
## _____ _ _ _ _ _ _ ##
|
3
|
-
## | ___| | | (_) | | | | | | | ##
|
4
|
-
## | |____ _____ ___ _ __ | |_ _ ___ _ __ | |_| | __ _ _ __ __| | | ___ _ __ ##
|
5
|
-
## | __\ \/ / __/ _ \ '_ \| __| |/ _ \| '_ \ | _ |/ _` | '_ \ / _` | |/ _ \ '__| ##
|
6
|
-
## | |___> < (_| __/ |_) | |_| | (_) | | | | | | | | (_| | | | | (_| | | __/ | ##
|
7
|
-
## \____/_/\_\___\___| .__/ \__|_|\___/|_| |_| \_| |_/\__,_|_| |_|\__,_|_|\___|_| ##
|
8
|
-
## | | ##
|
9
|
-
## |_| ##
|
10
|
-
########################################################################################
|
11
|
-
|
12
|
-
IMPORTANT -
|
13
|
-
**IF UPGRADING EXCEPTION HANDLER (to 0.4.7)***
|
14
|
-
**DELETE INITIALIZER (config/initializers/exception_handler.rb)**
|
15
|
-
|
16
|
-
We've changed the initialization process for ExceptionHandler.
|
17
|
-
|
18
|
-
The initializer has been replaced with /config/application.rb
|
19
|
-
options:
|
20
|
-
|
21
|
-
#config/application.rb
|
22
|
-
config.exception_handler = {
|
23
|
-
db: false, #-> defaults to :errors if true, else use :table_name
|
24
|
-
email: false, #-> need to integrate
|
25
|
-
social: {
|
26
|
-
:twitter => 'frontlineutils',
|
27
|
-
:facebook => 'frontline.utilities',
|
28
|
-
:linkedin => 'frontline-utilities',
|
29
|
-
:youtube => 'frontlineutils',
|
30
|
-
:fusion => 'frontlineutils',
|
31
|
-
:url => {
|
32
|
-
:facebook => 'https://facebook.com',
|
33
|
-
:twitter => 'http://twitter.com',
|
34
|
-
:youtube => 'https://youtube.com/user',
|
35
|
-
:linkedin => 'https://linkedin.com/company',
|
36
|
-
:fusion => 'https://frontlinefusion.com',
|
37
|
-
},
|
38
|
-
},
|
39
|
-
layouts: {
|
40
|
-
'400' => nil,
|
41
|
-
'500' => 'exception'
|
42
|
-
},
|
43
|
-
}
|
44
|
-
|
45
|
-
If you've made any changes to your initializer,
|
46
|
-
you MUST DELETE it, replacing the options with
|
47
|
-
those in config/application.rb, or
|
48
|
-
config/environments/production.rb.
|
49
|
-
|
50
|
-
More info on the ExceptionHandler github page:
|
51
|
-
http://github.com/richpeck/exception_handler
|
52
|
-
|
53
|
-
Thank you & enjoy!!
|
@@ -1,42 +0,0 @@
|
|
1
|
-
#####################################################
|
2
|
-
## _ _ _ ##
|
3
|
-
## | | | | | | ##
|
4
|
-
## | |_| | ___| |_ __ ___ _ __ ___ ##
|
5
|
-
## | _ |/ _ \ | '_ \ / _ \ '__/ __| ##
|
6
|
-
## | | | | __/ | |_) | __/ | \__ \ ##
|
7
|
-
## \_| |_/\___|_| .__/ \___|_| |___/ ##
|
8
|
-
## | | ##
|
9
|
-
## |_| ##
|
10
|
-
#####################################################
|
11
|
-
|
12
|
-
# Should reside in spec/**module**/helpers
|
13
|
-
# Testing specific helpers (in this case ApplicationHelper)
|
14
|
-
# Refs...
|
15
|
-
# http://stackoverflow.com/a/12846630/1143732
|
16
|
-
# https://github.com/rspec/rspec-rails#helper-specs
|
17
|
-
|
18
|
-
#####################################################
|
19
|
-
|
20
|
-
# Needs the RSpec helper / config
|
21
|
-
require 'spec_helper'
|
22
|
-
|
23
|
-
####
|
24
|
-
|
25
|
-
module ExceptionHandler
|
26
|
-
describe "ApplicationHelper", type: :helper do
|
27
|
-
|
28
|
-
# Defs
|
29
|
-
#let (:page) { ErrorPage.new exception, { "PATH_INFO" => "/some/path" } }
|
30
|
-
|
31
|
-
#####################################################
|
32
|
-
|
33
|
-
# "app" method
|
34
|
-
# https://www.relishapp.com/rspec/rspec-rails/v/2-0/docs/helper-specs/helper-spec
|
35
|
-
it "displays parent Rails app name" do
|
36
|
-
helper.app.should eql(Rails.application.class.parent_name)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
#####################################################
|
42
|
-
#####################################################
|