exception_handler 0.4.1 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/assets/stylesheets/exception_handler/error.css.erb +22 -10
- data/app/controllers/exception_handler/exception_controller.rb +15 -4
- data/app/helpers/exception_handler/application_helper.rb +32 -0
- data/app/models/exception_handler/error.rb +4 -0
- data/app/views/exception_handler/exception/show.html.erb +3 -3
- data/app/views/layouts/{error.html.erb → exception.html.erb} +2 -4
- data/exception_handler.gemspec +21 -19
- data/lib/exception_handler.rb +37 -22
- data/lib/exception_handler/config.rb +41 -18
- data/lib/exception_handler/parse.rb +23 -0
- data/lib/exception_handler/parser/data.rb +53 -0
- data/lib/exception_handler/parser/ignore.rb +32 -0
- data/lib/exception_handler/version.rb +2 -2
- data/lib/generators/exception_handler/migration_generator.rb +1 -1
- data/lib/generators/exception_handler/views_generator.rb +1 -1
- data/post_install_message.md +53 -0
- metadata +32 -9
- data/lib/exception_handler/parser.rb +0 -87
- data/lib/generators/exception_handler/install_generator.rb +0 -20
- data/lib/generators/templates/config.rb +0 -43
- data/spec/installation_spec.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71ba86443d6a75a89c634f589fa699e7da9b3d1f
|
4
|
+
data.tar.gz: 09d0e90fa92c55f15571be63bd00dd0274eccfac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 801a42bd1b0fb5effcd6ff29830c9c29f52cb8f65950e0c2a2b4d42c1dbbc2e9eff30742c1439fa576ad74cb9df663e17fdbebccdd29d95b077c80da8e894b44
|
7
|
+
data.tar.gz: d677c62c7d0887a93582b9d21a715a3798ec3e157073a437ce2f811c20b81117c3d4de378ebd289c62b80cb9446a13f15abfd75ed812b64cc0af5269b18ef6c9
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ Whilst it's common practice to use `config.exceptions_app = self.routes` to send
|
|
53
53
|
|
54
54
|
or
|
55
55
|
|
56
|
-
gem 'exception_handler', '~> 0.4' # Gemfile
|
56
|
+
gem 'exception_handler', '~> 0.4.5' # Gemfile
|
57
57
|
|
58
58
|
$ bundle
|
59
59
|
|
@@ -65,7 +65,7 @@ You can see [`ExceptionHandler` on RubyGems](https://rubygems.org/gems/exception
|
|
65
65
|
|
66
66
|
*Optional*
|
67
67
|
|
68
|
-
If you wish to change any of the default settings (listed below),
|
68
|
+
If you wish to change any of the default settings (listed below), you can now add `config.exception_handler` to your `config/application.rb` file:
|
69
69
|
|
70
70
|
$ rails g exception_handler:install
|
71
71
|
|
@@ -1,18 +1,23 @@
|
|
1
1
|
/* Vars */
|
2
|
-
<% size =
|
2
|
+
<% size = 18 %>
|
3
3
|
<% opacity = 0.85 %>
|
4
4
|
<% footer = 50 %>
|
5
5
|
<% radius = 5 %>
|
6
6
|
<% title_bg = "rgba(227,11,11,1)" %>
|
7
7
|
|
8
|
-
|
8
|
+
/**************/
|
9
9
|
/* Responsive */
|
10
|
+
/**************/
|
11
|
+
|
10
12
|
@media screen and (max-width: 950px) {
|
11
13
|
html { background-size: cover !important; }
|
12
14
|
.container .error { width: 55% !important; }
|
13
15
|
}
|
14
16
|
|
17
|
+
/***********/
|
15
18
|
/* Styling */
|
19
|
+
/***********/
|
20
|
+
|
16
21
|
* { margin: 0; }
|
17
22
|
html, body, .container { height: 100%; }
|
18
23
|
html {
|
@@ -138,7 +143,9 @@ a:hover { text-decoration: underline; }
|
|
138
143
|
}
|
139
144
|
.container .message .title a.close:hover img { opacity: 0.75; }
|
140
145
|
|
141
|
-
|
146
|
+
/***********/
|
147
|
+
/* Details */
|
148
|
+
/***********/
|
142
149
|
|
143
150
|
.container .message .details {
|
144
151
|
position: relative;
|
@@ -254,18 +261,22 @@ a:hover { text-decoration: underline; }
|
|
254
261
|
.container .message > .info .notification a.home:hover { opacity: <%= opacity %>; }
|
255
262
|
.container .message > .info .notification a.home img { height: 12px; }
|
256
263
|
|
264
|
+
/**********/
|
257
265
|
/* Footer */
|
266
|
+
/**********/
|
267
|
+
|
258
268
|
footer {
|
259
269
|
display: block;
|
260
270
|
position: relative;
|
261
271
|
vertical-align: middle;
|
262
272
|
clear: both;
|
263
273
|
color: #fff;
|
264
|
-
margin: 15px
|
265
|
-
padding: 14px
|
274
|
+
margin: 15px 2% 0;
|
275
|
+
padding: 14px 0;
|
266
276
|
box-sizing: border-box;
|
267
277
|
max-height: <%= footer %>;
|
268
278
|
z-index: 1100;
|
279
|
+
border-top: 1px solid rgba(255,255,255,0.1);
|
269
280
|
}
|
270
281
|
|
271
282
|
footer .app { text-transform: uppercase; }
|
@@ -286,12 +297,13 @@ footer .connect a {
|
|
286
297
|
padding-left: 4px;
|
287
298
|
margin: 0 -1px; /* Use 0 -1px for inline block & ERB - HAML removes whitespace; ERB does now - http://haml.info/docs/yardoc/file.REFERENCE.html#whitespace_removal__and_ */
|
288
299
|
transition: opacity 0.2s ease;
|
300
|
+
vertical-align: middle;
|
289
301
|
}
|
290
302
|
|
291
|
-
footer .connect a img { display: block;
|
292
|
-
footer .connect a.facebook img { height: <%= size * 0.
|
293
|
-
footer .connect a.twitter img { height: <%= size * 0.
|
294
|
-
footer .connect a.
|
295
|
-
footer .connect a.
|
303
|
+
footer .connect a img { display: block; padding: 0 5px; }
|
304
|
+
footer .connect a.facebook img { height: <%= size * 0.92 %>px; }
|
305
|
+
footer .connect a.twitter img { height: <%= size * 0.88 %>px; }
|
306
|
+
footer .connect a.youtube img { height: <%= size %>px; }
|
307
|
+
footer .connect a.linkedin img { height: <%= size * 0.97 %>px; }
|
296
308
|
footer .connect a.fusion img { height: <%= size %>px; }
|
297
309
|
footer .connect:hover a:hover { opacity: 1; }
|
@@ -10,6 +10,10 @@ module ExceptionHandler
|
|
10
10
|
#Layout
|
11
11
|
layout :layout_status
|
12
12
|
|
13
|
+
#Helpers
|
14
|
+
helper ExceptionHandler::ApplicationHelper #-> HELPERS http://stackoverflow.com/questions/9809787/why-is-my-rails-mountable-engine-not-loading-helper-methods-correctly
|
15
|
+
include Rails.application.routes.url_helpers #-> ROUTES http://stackoverflow.com/a/6074911/1143732
|
16
|
+
|
13
17
|
####################
|
14
18
|
# Action #
|
15
19
|
####################
|
@@ -17,8 +21,15 @@ module ExceptionHandler
|
|
17
21
|
#Show
|
18
22
|
def show
|
19
23
|
@layout = self.send(:_layout)
|
20
|
-
@message = @status
|
21
|
-
|
24
|
+
@message = (/^(5[0-9]{2})$/ !~ @status.to_s) ? "Sorry, this page is missing" : details[:message]
|
25
|
+
|
26
|
+
## Config "404 block" handler ##
|
27
|
+
if /^(5[0-9]{2})$/ !~ @status.to_s && ExceptionHandler.config["404"] #-> http://www.justskins.com/forums/ruby-s-regexp-is-52846.html
|
28
|
+
eval ExceptionHandler.config["404"]
|
29
|
+
else
|
30
|
+
## Render (if eval do anything) ##
|
31
|
+
render status: @status
|
32
|
+
end
|
22
33
|
end
|
23
34
|
|
24
35
|
####################
|
@@ -55,9 +66,9 @@ module ExceptionHandler
|
|
55
66
|
def layout_status
|
56
67
|
case @status
|
57
68
|
when 404
|
58
|
-
ExceptionHandler.config
|
69
|
+
ExceptionHandler.config[:layouts]["400"] || nil #-> inherits ApplicationController layout
|
59
70
|
else
|
60
|
-
ExceptionHandler.config
|
71
|
+
ExceptionHandler.config[:layouts]["500"] #-> should pull default if none sepecified
|
61
72
|
end
|
62
73
|
end
|
63
74
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ExceptionHandler
|
2
|
+
module ApplicationHelper
|
3
|
+
|
4
|
+
#Refs
|
5
|
+
#http://stackoverflow.com/a/5795683/1143732
|
6
|
+
#http://stackoverflow.com/questions/8028021/helpers-in-rails-engine
|
7
|
+
#ActiveSupport.on_load( :action_view ){ include ExceptionHandler::ViewHelpers }
|
8
|
+
|
9
|
+
#Social
|
10
|
+
def social *services
|
11
|
+
output = []
|
12
|
+
# options = args.extract_options! http://simonecarletti.com/blog/2009/09/inside-ruby-on-rails-extract_options-from-arrays/ - args for arrays
|
13
|
+
|
14
|
+
services = ExceptionHandler.config[:social] unless services.any?
|
15
|
+
services.except(:url).each do |service,username| #-> except http://stackoverflow.com/a/11105831/1143732
|
16
|
+
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)
|
17
|
+
end
|
18
|
+
|
19
|
+
output.join("").html_safe #-> ruby returns last line
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def link service #-> bloated way to allow single references in config
|
25
|
+
url = []
|
26
|
+
url.push ExceptionHandler.config[:social][:url][service]
|
27
|
+
url.push ExceptionHandler.config[:social][service]
|
28
|
+
url.join("/")
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -2,8 +2,12 @@ module ExceptionHandler
|
|
2
2
|
class Error < ActiveRecord::Base
|
3
3
|
#Table is called "errors"
|
4
4
|
#Dev needs to use migration to create db
|
5
|
+
def self.table_name
|
6
|
+
ExceptionHandler.config[:db]
|
7
|
+
end
|
5
8
|
|
6
9
|
#Associations
|
7
10
|
belongs_to :usable, polymorphic: true
|
11
|
+
|
8
12
|
end
|
9
13
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
<div class="error">
|
2
|
-
<% if
|
2
|
+
<% if /^(5[0-9]{2})$/ =~ @status.to_s %>
|
3
3
|
|
4
4
|
<!--Message -->
|
5
5
|
<%= content_tag :div, class: "message" do %>
|
6
6
|
<%= content_tag :div, class: "title" do %>
|
7
7
|
<span><%= "#{@status} Error - #{details[:name]}" %></span>
|
8
|
-
<%= link_to image_tag("exception_handler/close.png"), root_url, title: "Close (Go back home)", class: "close" %>
|
8
|
+
<%= link_to image_tag("exception_handler/close.png"), main_app.root_url, title: "Close (Go back home)", class: "close" %>
|
9
9
|
<% end %>
|
10
10
|
<%= content_tag :div, class: "details" do %>
|
11
11
|
<%= image_tag "exception_handler/alert.png", title: "#{@status} Error" %>
|
@@ -14,7 +14,7 @@
|
|
14
14
|
<%= content_tag :div, class: "info" do %>
|
15
15
|
<span><%= @message %></span>
|
16
16
|
<div class="notification">
|
17
|
-
<%= link_to image_tag("exception_handler/home.png", title: "Go Back Home"), root_url, class: "home" %>
|
17
|
+
<%= link_to image_tag("exception_handler/home.png", title: "Go Back Home"), main_app.root_url, class: "home" %>
|
18
18
|
<div class="version">v<%= Rails.version %></div>
|
19
19
|
<strong>Our developers have been notified - we're working on it!</strong>
|
20
20
|
</div>
|
@@ -17,12 +17,10 @@
|
|
17
17
|
<!-- Footer -->
|
18
18
|
<footer>
|
19
19
|
<div class="connect">
|
20
|
-
|
21
|
-
<%= link_to image_tag("exception_handler/connect/#{item}.png", title: "Find us on " + item.to_s.titleize), address, target: :blank, class: item.to_s %>
|
22
|
-
<% end %>
|
20
|
+
<%= social %>
|
23
21
|
</div>
|
24
22
|
<div class="app">
|
25
|
-
<strong><%= link_to @app_name, root_url, title: "Go to index" %></strong>
|
23
|
+
<strong><%= link_to @app_name, main_app.root_url, title: "Go to index" %></strong>
|
26
24
|
<span> - <%= @status %> Error</span>
|
27
25
|
</div>
|
28
26
|
</footer>
|
data/exception_handler.gemspec
CHANGED
@@ -3,25 +3,27 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'exception_handler/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "exception_handler"
|
8
|
+
s.version = ExceptionHandler::VERSION
|
9
|
+
s.authors = ["Richard Peck", "Joe Hilton"]
|
10
|
+
s.email = ["rpeck@frontlineutilities.co.uk", "jhilton@frontlineutilities.co.uk"]
|
11
|
+
s.summary = %q{Rails gem to show custom error pages in production. Also logs errors in "errors" db if required}
|
12
|
+
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.}
|
13
|
+
s.homepage = "http://frontlineutilities.co.uk/ror/custom_error_pages"
|
14
|
+
s.license = "MIT"
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
s.files = `git ls-files -z`.split("\x0")
|
17
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
|
+
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
s.post_install_message = File.read(File.join(File.dirname(__FILE__), 'post_install_message.md')) #-> https://github.com/jarrett/ichiban/blob/master/ichiban.gemspec#L35
|
22
|
+
|
23
|
+
s.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
s.add_development_dependency "rails", "~> 4.0.0"
|
25
|
+
s.add_development_dependency "activerecord"
|
26
|
+
s.add_development_dependency "activesupport"
|
27
|
+
s.add_development_dependency "rake"
|
28
|
+
s.add_development_dependency "rspec"
|
27
29
|
end
|
data/lib/exception_handler.rb
CHANGED
@@ -3,41 +3,56 @@
|
|
3
3
|
#Core Dependencies
|
4
4
|
require "action_dispatch"
|
5
5
|
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
#Libs
|
7
|
+
#http://stackoverflow.com/a/4528011/1143732
|
8
|
+
#http://stackoverflow.com/a/21693468/1143732
|
9
|
+
#https://github.com/jekyll/jekyll/blob/master/lib/jekyll.rb#L8
|
10
|
+
Dir.glob(File.join(File.dirname(__FILE__), "exception_handler", '**/*.rb'), &method(:require))
|
11
11
|
|
12
12
|
###########################################
|
13
13
|
|
14
14
|
module ExceptionHandler
|
15
15
|
|
16
|
+
#Version
|
17
|
+
autoload :VERSION, 'exception_handler/version'
|
18
|
+
|
19
|
+
#Config
|
20
|
+
#https://github.com/thoughtbot/paperclip/blob/523bd46c768226893f23889079a7aa9c73b57d68/lib/paperclip/railtie.rb#L13
|
21
|
+
mattr_accessor :config
|
22
|
+
@@config = ExceptionHandler::Config.defaults #-> instance of defaults invoked with @@config, merged with deep_merge
|
23
|
+
|
24
|
+
# Don't have prefix method return anything.
|
25
|
+
# This will keep Rails Engine from generating all table prefixes with the engines name
|
26
|
+
# http://stackoverflow.com/questions/19435214/rails-mountable-engine-with-isolate-namespace-but-without-prefixed-namespace-on
|
27
|
+
def self.table_name_prefix
|
28
|
+
#No prefix
|
29
|
+
end
|
30
|
+
|
16
31
|
#Exception Handler
|
17
32
|
class Exceptions < Rails::Engine
|
33
|
+
#Keep helpers in your engine
|
34
|
+
#http://guides.rubyonrails.org/engines.html#inside-an-engine
|
35
|
+
#http://stackoverflow.com/questions/31877839/accessing-helpers-from-the-parent-app-in-an-isolated-rails-engine
|
36
|
+
#use main_app to call "main app" helpers etc http://stackoverflow.com/a/9178022/1143732 + http://edgeapi.rubyonrails.org/classes/Rails/Engine.html#class-Rails::Engine-label-Using+Engine-27s+routes+outside+Engine
|
37
|
+
isolate_namespace ExceptionHandler
|
18
38
|
|
19
39
|
#Stylesheet
|
20
40
|
config.assets.precompile += %w(exception_handler/error.css)
|
21
41
|
|
22
|
-
#
|
42
|
+
#Config
|
43
|
+
@@config = ExceptionHandler.config
|
44
|
+
|
45
|
+
#Hook
|
23
46
|
initializer "exception_handler.configure_rails_initialization" do |app|
|
24
|
-
|
25
|
-
|
47
|
+
|
48
|
+
#Options
|
49
|
+
@@config.deep_merge! app.config.exception_handler if app.config.respond_to? :exception_handler
|
50
|
+
@@config[:db] = ExceptionHandler::Config::TABLE_NAME if @@config[:db] == true
|
51
|
+
|
52
|
+
#Middleware
|
53
|
+
app.config.middleware.use ExceptionHandler::Parse if @@config[:db] # && ActiveRecord::Base.connection.table_exists?(:errors unless @@config[:db].blank?) #DB
|
54
|
+
app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionController.action(:show).call(env) } #Controller
|
26
55
|
end
|
27
56
|
|
28
57
|
end
|
29
|
-
|
30
|
-
####################
|
31
|
-
# Config #
|
32
|
-
####################
|
33
|
-
|
34
|
-
mattr_accessor :config, :table
|
35
|
-
|
36
|
-
#Vars
|
37
|
-
@@config ||= Config.new
|
38
|
-
|
39
|
-
#Block (for initializer)
|
40
|
-
def self.setup
|
41
|
-
yield(config) if block_given?
|
42
|
-
end
|
43
58
|
end
|
@@ -7,24 +7,47 @@
|
|
7
7
|
###########################################
|
8
8
|
|
9
9
|
module ExceptionHandler
|
10
|
-
|
11
|
-
|
10
|
+
class Config
|
11
|
+
mattr_accessor :db, :email, :table, :social, :layouts
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
#Default Table Name
|
14
|
+
# Has to be "errors" because "exceptions" is a reserved word
|
15
|
+
TABLE_NAME = :errors
|
16
|
+
|
17
|
+
# Defaults
|
18
|
+
# Merged with Rails options with @@config in engine
|
19
|
+
def self.defaults
|
20
|
+
{
|
21
|
+
db: false, #-> defaults to :errors if true, else use :table_name
|
22
|
+
email: false, #-> need to integrate
|
23
|
+
social: {
|
24
|
+
:facebook => 'frontline.utilities',
|
25
|
+
:twitter => 'frontlineutils',
|
26
|
+
:youtube => 'frontlineutils',
|
27
|
+
:linkedin => 'frontline-utilities',
|
28
|
+
:fusion => 'frontlineutils',
|
29
|
+
:url => {
|
30
|
+
:facebook => 'https://facebook.com',
|
31
|
+
:twitter => 'http://twitter.com',
|
32
|
+
:youtube => 'https://youtube.com/user',
|
33
|
+
:linkedin => 'https://linkedin.com/company',
|
34
|
+
:fusion => 'https://frontlinefusion.com',
|
35
|
+
},
|
36
|
+
},
|
37
|
+
layouts: {
|
38
|
+
'400' => nil,
|
39
|
+
'500' => 'exception'
|
40
|
+
},
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
#404 Callback (needs improving big time)
|
45
|
+
#Use the following:
|
16
46
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
youtube: "https://youtube.com/user/frontlineutils",
|
24
|
-
fusion: "http://frontlinefusion.com/frontlineutils"
|
25
|
-
}
|
26
|
-
@error_layout = nil
|
27
|
-
@exception_layout = nil
|
28
|
-
end
|
29
|
-
end
|
47
|
+
#'404' => <<-EOF
|
48
|
+
# redirect_to root_url, notice: "Hello"
|
49
|
+
#EOF
|
50
|
+
|
51
|
+
#This will invoke specifics for the
|
52
|
+
end
|
30
53
|
end
|
@@ -0,0 +1,23 @@
|
|
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 = env['action_controller.instance']
|
16
|
+
ignore = ExceptionHandler::Parser::Ignore.new(exception, request).match?
|
17
|
+
|
18
|
+
ExceptionHandler::Parser::Data.new(exception, request, controller).save unless ignore
|
19
|
+
raise exception
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module ExceptionHandler
|
2
|
+
module Parser
|
3
|
+
class Data
|
4
|
+
|
5
|
+
#Init
|
6
|
+
def initialize(exception, request, controller)
|
7
|
+
@exception, @request, @controller, @user = exception, request, controller, user
|
8
|
+
end
|
9
|
+
|
10
|
+
#Save
|
11
|
+
def save
|
12
|
+
#http://blog.habanerohq.com/post/16800611137/selectively-silence-activerecord-logging
|
13
|
+
message = ""
|
14
|
+
ActiveRecord::Base.logger.silence do
|
15
|
+
ExceptionHandler::Error.create info do |error|
|
16
|
+
message += "\n======================\n"
|
17
|
+
message += "#{error.class_name}:\n"
|
18
|
+
message += "\n#{error.message}\n"
|
19
|
+
message += Rails.backtrace_cleaner.clean(error.trace.split("\n")).join("\n")
|
20
|
+
message += "\n======================\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
Rails.logger.fatal message unless message.blank?
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
#User
|
29
|
+
def user
|
30
|
+
@controller.send(:current_user) if @controller.respond_to?(:current_user)
|
31
|
+
end
|
32
|
+
|
33
|
+
#Info
|
34
|
+
def info
|
35
|
+
info = {
|
36
|
+
class_name: @exception.class.to_s,
|
37
|
+
message: @exception.message.to_s,
|
38
|
+
trace: @exception.backtrace.join("\n"),
|
39
|
+
target_url: @request.url,
|
40
|
+
referer_url: @request.referer,
|
41
|
+
params: @request.params.inspect,
|
42
|
+
user_agent: @request.user_agent
|
43
|
+
}
|
44
|
+
if @user && @user.respond_to(:id)
|
45
|
+
info[:usable_type] = @user.model_name.human
|
46
|
+
info[:usable_id] = @user.id
|
47
|
+
end
|
48
|
+
return info
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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
|
+
Array(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
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module ExceptionHandler
|
2
|
-
|
3
|
-
end
|
2
|
+
VERSION = "0.4.6"
|
3
|
+
end
|
@@ -21,7 +21,7 @@ module ExceptionHandler
|
|
21
21
|
#Table Name - false = off, true = errors, value = value
|
22
22
|
#Always outputs string for some reason...
|
23
23
|
def table_name
|
24
|
-
ExceptionHandler.config
|
24
|
+
ExceptionHandler.config[:db]
|
25
25
|
end
|
26
26
|
|
27
27
|
###########################################
|
@@ -2,7 +2,7 @@ module ExceptionHandler
|
|
2
2
|
class ViewsGenerator < Rails::Generators::Base
|
3
3
|
|
4
4
|
#Views
|
5
|
-
@@views = %w(views controllers models assets)
|
5
|
+
@@views = %w(views controllers helpers models assets)
|
6
6
|
|
7
7
|
#Options
|
8
8
|
class_option :files, aliases: "-v", default: @@views, type: :array, desc: "Select file types (views, models, controllers, assets)"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
########################################################################################
|
2
|
+
## _____ _ _ _ _ _ _ ##
|
3
|
+
## | ___| | | (_) | | | | | | | ##
|
4
|
+
## | |____ _____ ___ _ __ | |_ _ ___ _ __ | |_| | __ _ _ __ __| | | ___ _ __ ##
|
5
|
+
## | __\ \/ / __/ _ \ '_ \| __| |/ _ \| '_ \ | _ |/ _` | '_ \ / _` | |/ _ \ '__| ##
|
6
|
+
## | |___> < (_| __/ |_) | |_| | (_) | | | | | | | | (_| | | | | (_| | | __/ | ##
|
7
|
+
## \____/_/\_\___\___| .__/ \__|_|\___/|_| |_| \_| |_/\__,_|_| |_|\__,_|_|\___|_| ##
|
8
|
+
## | | ##
|
9
|
+
## |_| ##
|
10
|
+
########################################################################################
|
11
|
+
|
12
|
+
IMPORTANT -
|
13
|
+
**IF UPGRADING EXCEPTION HANDLER (to 0.4.5)***
|
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!!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exception_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Peck
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-12-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -126,19 +126,21 @@ files:
|
|
126
126
|
- app/assets/images/exception_handler/overlay.png
|
127
127
|
- app/assets/stylesheets/exception_handler/error.css.erb
|
128
128
|
- app/controllers/exception_handler/exception_controller.rb
|
129
|
+
- app/helpers/exception_handler/application_helper.rb
|
129
130
|
- app/models/exception_handler/error.rb
|
130
131
|
- app/views/exception_handler/exception/show.html.erb
|
131
|
-
- app/views/layouts/
|
132
|
+
- app/views/layouts/exception.html.erb
|
132
133
|
- exception_handler.gemspec
|
133
134
|
- lib/exception_handler.rb
|
134
135
|
- lib/exception_handler/config.rb
|
135
|
-
- lib/exception_handler/
|
136
|
+
- lib/exception_handler/parse.rb
|
137
|
+
- lib/exception_handler/parser/data.rb
|
138
|
+
- lib/exception_handler/parser/ignore.rb
|
136
139
|
- lib/exception_handler/version.rb
|
137
|
-
- lib/generators/exception_handler/install_generator.rb
|
138
140
|
- lib/generators/exception_handler/migration_generator.rb
|
139
141
|
- lib/generators/exception_handler/views_generator.rb
|
140
|
-
- lib/generators/templates/config.rb
|
141
142
|
- lib/generators/templates/migration.rb.erb
|
143
|
+
- post_install_message.md
|
142
144
|
- readme/400.jpg
|
143
145
|
- readme/500.jpg
|
144
146
|
- readme/application_controller.jpg
|
@@ -155,13 +157,35 @@ files:
|
|
155
157
|
- readme/subtitle.jpg
|
156
158
|
- readme/title.png
|
157
159
|
- readme/view.jpg
|
158
|
-
- spec/installation_spec.rb
|
159
160
|
- spec/spec_helper.rb
|
160
161
|
homepage: http://frontlineutilities.co.uk/ror/custom_error_pages
|
161
162
|
licenses:
|
162
163
|
- MIT
|
163
164
|
metadata: {}
|
164
|
-
post_install_message:
|
165
|
+
post_install_message: "########################################################################################\n##
|
166
|
+
\ _____ _ _ _ _ _ _ ##\n##
|
167
|
+
| ___| | | (_) | | | | | | | ##\n##
|
168
|
+
| |____ _____ ___ _ __ | |_ _ ___ _ __ | |_| | __ _ _ __ __| | | ___ _ __
|
169
|
+
\ ##\n## | __\\ \\/ / __/ _ \\ '_ \\| __| |/ _ \\| '_ \\ | _ |/ _` | '_ \\
|
170
|
+
/ _` | |/ _ \\ '__| ##\n## | |___> < (_| __/ |_) | |_| | (_) | | | | | | | |
|
171
|
+
(_| | | | | (_| | | __/ | ##\n## \\____/_/\\_\\___\\___| .__/ \\__|_|\\___/|_|
|
172
|
+
|_| \\_| |_/\\__,_|_| |_|\\__,_|_|\\___|_| ## \n## | | ##\n##
|
173
|
+
\ |_| ##\n########################################################################################\n\nIMPORTANT
|
174
|
+
-\n**IF UPGRADING EXCEPTION HANDLER (to 0.4.5)***\n**DELETE INITIALIZER (config/initializers/exception_handler.rb)**\n\nWe've
|
175
|
+
changed the initialization process for ExceptionHandler.\n\nThe initializer has
|
176
|
+
been replaced with /config/application.rb\noptions:\n\n#config/application.rb\nconfig.exception_handler
|
177
|
+
= {\n\tdb: \tfalse, #-> defaults to :errors if true, else use :table_name\n\temail:
|
178
|
+
\tfalse, #-> need to integrate\n\tsocial: {\n\t :twitter \t=> \t'frontlineutils',\n\t
|
179
|
+
\ :facebook \t=> \t'frontline.utilities',\n\t :linkedin \t=> \t'frontline-utilities',\n\t
|
180
|
+
\ :youtube \t=>\t'frontlineutils',\n\t :fusion \t=> \t'frontlineutils',\n\t
|
181
|
+
\ :url => {\n\t\t :facebook \t=> \t'https://facebook.com',\n\t\t :twitter
|
182
|
+
\t=> \t'http://twitter.com',\n\t\t :youtube \t=>\t'https://youtube.com/user',\n\t\t
|
183
|
+
\ :linkedin \t=> \t'https://linkedin.com/company',\n\t\t :fusion \t=> \t'https://frontlinefusion.com',\n\t\t},\n\t},\n\tlayouts:
|
184
|
+
{\n\t '400' => nil,\n\t '500' => 'exception'\n\t},\n}\n\nIf you've made any
|
185
|
+
changes to your initializer,\nyou MUST DELETE it, replacing the options with\nthose
|
186
|
+
in config/application.rb, or\nconfig/environments/production.rb.\n\nMore info on
|
187
|
+
the ExceptionHandler github page:\nhttp://github.com/richpeck/exception_handler\n\nThank
|
188
|
+
you & enjoy!!"
|
165
189
|
rdoc_options: []
|
166
190
|
require_paths:
|
167
191
|
- lib
|
@@ -183,5 +207,4 @@ specification_version: 4
|
|
183
207
|
summary: Rails gem to show custom error pages in production. Also logs errors in "errors"
|
184
208
|
db if required
|
185
209
|
test_files:
|
186
|
-
- spec/installation_spec.rb
|
187
210
|
- spec/spec_helper.rb
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module ExceptionHandler
|
2
|
-
|
3
|
-
#Message
|
4
|
-
class Message
|
5
|
-
|
6
|
-
# Init
|
7
|
-
def initialize(app)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
#Error
|
12
|
-
def call(env)
|
13
|
-
@app.call(env)
|
14
|
-
|
15
|
-
rescue Exception => exception
|
16
|
-
request = ActionDispatch::Request.new(env)
|
17
|
-
controller = env['action_controller.instance']
|
18
|
-
|
19
|
-
ExceptionHandler::Parser.new(exception, request, controller).save unless self.ignore?(exception, request)
|
20
|
-
raise exception
|
21
|
-
end
|
22
|
-
|
23
|
-
#Ignore
|
24
|
-
def ignore?(exception, request, ignored = {})
|
25
|
-
ignored[:errors] = [ActionController::RoutingError, AbstractController::ActionNotFound, ActiveRecord::RecordNotFound]
|
26
|
-
ignored[:bots] = /\b(Baidu|Gigabot|Googlebot|libwww-per|lwp-trivial|msnbot|SiteUptime|Slurp|Wordpress|ZIBB|ZyBorg|Yandex|Jyxobot|Huaweisymantecspider|ApptusBot)\b/i
|
27
|
-
|
28
|
-
return true if ignored[:errors].include?(exception.class) && request.referer.blank?
|
29
|
-
return true if request.user_agent =~ ignored[:bots]
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
#Parse
|
35
|
-
class Parser
|
36
|
-
|
37
|
-
#Init
|
38
|
-
def initialize(exception, request, controller)
|
39
|
-
@exception, @request, @controller = exception, request, controller
|
40
|
-
end
|
41
|
-
|
42
|
-
#Save
|
43
|
-
def save
|
44
|
-
ActiveRecord::Base.logger.silence do
|
45
|
-
ExceptionHandler::Error.create(relevant_info)
|
46
|
-
end
|
47
|
-
log(relevant_info)
|
48
|
-
end
|
49
|
-
|
50
|
-
#Info
|
51
|
-
def relevant_info(info = {})
|
52
|
-
info[:class_name] = @exception.class.to_s
|
53
|
-
info[:message] = @exception.to_s
|
54
|
-
info[:trace] = @exception.backtrace.join("\n")
|
55
|
-
info[:target_url] = @request.url
|
56
|
-
info[:referer_url] = @request.referer
|
57
|
-
info[:params] = @request.params.inspect
|
58
|
-
info[:user_agent] = @request.user_agent
|
59
|
-
if user
|
60
|
-
info[:usable_type] = user[:type]
|
61
|
-
info[:usable_id] = user[:id]
|
62
|
-
end
|
63
|
-
return info
|
64
|
-
end
|
65
|
-
|
66
|
-
#User
|
67
|
-
def user(data = {})
|
68
|
-
# => refer to Joe's if want to find admin / user
|
69
|
-
if(@controller.respond_to?("current_user"))
|
70
|
-
user = @controller.send("current_user")
|
71
|
-
[:id].each do |field|
|
72
|
-
data[:id] = user.send(field) if user.respond_to?(field)
|
73
|
-
data[:type] = "User" if @controller.respond_to?("current_user")
|
74
|
-
end
|
75
|
-
end
|
76
|
-
return data
|
77
|
-
end
|
78
|
-
|
79
|
-
#Log
|
80
|
-
def log(info)
|
81
|
-
message = "#{info[:class_name]} (#{info[:message]}):\n "
|
82
|
-
message += Rails.backtrace_cleaner.clean(info[:trace].split("\n")).join("\n")
|
83
|
-
Rails.logger.fatal(message)
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module ExceptionHandler
|
2
|
-
class Generators
|
3
|
-
class InstallGenerator < Rails::Generators::Base
|
4
|
-
|
5
|
-
#Needed to reference files
|
6
|
-
source_root File.expand_path("../../templates", __FILE__)
|
7
|
-
|
8
|
-
###########################################
|
9
|
-
|
10
|
-
#Config
|
11
|
-
def create_config_file
|
12
|
-
return unless options.empty?
|
13
|
-
template "config.rb", "config/initializers/exception_handler.rb" # https://github.com/plataformatec/devise/blob/master/lib/generators/devise/install_generator.rb#L13
|
14
|
-
end
|
15
|
-
|
16
|
-
###########################################
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
#################################################################################################
|
2
|
-
## ##
|
3
|
-
## ______ __ _ __ __ ____ ##
|
4
|
-
## / ____/ __________ ____ / /_(_)___ ____ / / / /___ _____ ____/ / /__ _____ ##
|
5
|
-
## / __/ | |/_/ ___/ _ \/ __ \/ __/ / __ \/ __ \ / /_/ / __ `/ __ \/ __ / / _ \/ ___/ ##
|
6
|
-
## / /____> </ /__/ __/ /_/ / /_/ / /_/ / / / / / __ / /_/ / / / / /_/ / / __/ / ##
|
7
|
-
## /_____/_/|_|\___/\___/ .___/\__/_/\____/_/ /_/ /_/ /_/\__,_/_/ /_/\__,_/_/\___/_/ ##
|
8
|
-
## /_/ ##
|
9
|
-
## ##
|
10
|
-
#################################################################################################
|
11
|
-
# You can add different settings using this file #
|
12
|
-
# Use the docs at http://github.com/richpeck/exception_handler for info #
|
13
|
-
#################################################################################################
|
14
|
-
|
15
|
-
# config/initializers/exception_handler.rb
|
16
|
-
ExceptionHandler.setup do |config|
|
17
|
-
|
18
|
-
# DB -
|
19
|
-
# false / true / :table_name (must exist)
|
20
|
-
config.db = false
|
21
|
-
|
22
|
-
# Exception Layout (for 500 errors, defaults to Error)
|
23
|
-
# false / name (str or sym)
|
24
|
-
#config.exception_layout = :your_name
|
25
|
-
|
26
|
-
# Error Layout (for 400 errors, defaults to Application)
|
27
|
-
# false / name (str or sym)
|
28
|
-
#config.error_layout = :your_name
|
29
|
-
|
30
|
-
# Email -
|
31
|
-
# false / true
|
32
|
-
# config.email =
|
33
|
-
|
34
|
-
# Social
|
35
|
-
config.social = {
|
36
|
-
twitter: 'http://twitter.com/frontlineutils',
|
37
|
-
facebook: 'https://facebook.com/frontline.utilities',
|
38
|
-
linkedin: 'https://linkedin.com/company/frontline-utilities',
|
39
|
-
youtube: 'https://youtube.com/user/frontlineutils',
|
40
|
-
fusion: 'http://frontlinefusion.com/frontlineutils'
|
41
|
-
}
|
42
|
-
|
43
|
-
end
|
data/spec/installation_spec.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
###########################################
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
###########################################
|
6
|
-
|
7
|
-
class InstallationSpec < Rails::Generators::TestCase
|
8
|
-
|
9
|
-
#Setup
|
10
|
-
tests ExceptionHandler::Generators::InstallGenerator
|
11
|
-
destination File.expand_path("../../tmp", __FILE__)
|
12
|
-
|
13
|
-
#Before
|
14
|
-
setup do
|
15
|
-
prepare_destination
|
16
|
-
run_generator
|
17
|
-
end
|
18
|
-
|
19
|
-
#Config Installer
|
20
|
-
test "assert Config Files Are Created" do
|
21
|
-
assert_file "config/initializers/exception_handler.rb"
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|