exception_handler 0.0.25 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile +2 -2
- data/README.md +35 -6
- data/app/controllers/exception_handler/exception_controller.rb +58 -0
- data/app/views/exception_handler/exception/show.html.haml +5 -0
- data/app/views/layouts/error.html.haml +57 -0
- data/exception_handler.gemspec +9 -10
- data/lib/exception_handler.rb +8 -36
- data/lib/exception_handler/parser.rb +35 -2
- data/lib/exception_handler/version.rb +2 -2
- data/vendor/assets/images/exception_handler/bg.png +0 -0
- metadata +47 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1e32a60e6d820806fc19a72664d3713630b4986
|
4
|
+
data.tar.gz: 6ba577f2b71bc13222d2cfa88a970736c53fc089
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c9bc99f7043be2a6266afed2ecabca7f01927565f8098e85d607dd533df13eb3f8ca5a8b8e84f93d34586a2c942a08c4d2d9e00f3b13163c9cd6229242277ce
|
7
|
+
data.tar.gz: f13e51b07425ace2e5849859861f076d8b2c36c2f63be93b0853c399c7f1f13aa3e89b8a0ca18de9860a4c3b9958d161032078e1345e73b09d9443dcc95547f7
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
# ExceptionHandler
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/exception_handler.svg)](http://badge.fury.io/rb/exception_handler)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/richpeck/exception_handler.png)](https://codeclimate.com/github/richpeck/exception_handler)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/richpeck/exception_handler/badge.png)](https://coveralls.io/r/richpeck/exception_handler)
|
6
|
+
[![Build Status](https://travis-ci.org/richpeck/exception_handler.svg?branch=master)](https://travis-ci.org/richpeck/exception_handler)
|
4
7
|
|
5
|
-
|
6
|
-
Second, it includes an `exception` controller to route your errors to specific pages.
|
8
|
+
**ExceptionHandler** Rails Gem (adapted from [this tutorial](https://gist.github.com/wojtha/8433843))
|
7
9
|
|
8
|
-
|
10
|
+
Works with the [`config.exceptions_app`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration) hook in Rails' middleware stack:
|
11
|
+
|
12
|
+
```config.exceptions_app sets the exceptions application invoked by the ShowException middleware when an exception happens. Defaults to ActionDispatch::PublicExceptions.new(Rails.public_path).```
|
13
|
+
|
14
|
+
|
15
|
+
---------
|
9
16
|
|
10
17
|
## Installation
|
11
18
|
|
@@ -21,8 +28,30 @@ Or install it yourself as:
|
|
21
28
|
|
22
29
|
$ gem install exception_handler
|
23
30
|
|
31
|
+
---------
|
32
|
+
|
24
33
|
## Usage
|
25
34
|
|
26
|
-
|
35
|
+
###Dev
|
36
|
+
|
37
|
+
#config/environments/development.rb
|
38
|
+
config.consider_all_requests_local = false # true
|
39
|
+
|
40
|
+
`config.exceptions_app` is used in Rails' production environment. Therefore, if you wish to test the gem in dev,
|
41
|
+
you'll need to make your app process requests as `production` for now. This is a temporary step, and will be
|
42
|
+
resolved in a new version
|
43
|
+
|
44
|
+
###Production
|
45
|
+
|
46
|
+
No action required
|
47
|
+
|
48
|
+
|
49
|
+
--------
|
50
|
+
|
51
|
+
## Contributing
|
27
52
|
|
28
|
-
|
53
|
+
1. Fork it ( https://github.com/richpeck/exception_handler/fork )
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module ExceptionHandler
|
2
|
+
class ExceptionController < ApplicationController
|
3
|
+
|
4
|
+
#Response
|
5
|
+
respond_to :html, :xml, :json
|
6
|
+
|
7
|
+
#Dependencies
|
8
|
+
before_action :status
|
9
|
+
|
10
|
+
#Layout
|
11
|
+
layout :layout_status
|
12
|
+
|
13
|
+
####################
|
14
|
+
# Action #
|
15
|
+
####################
|
16
|
+
|
17
|
+
#Show
|
18
|
+
def show
|
19
|
+
respond_with status: @status
|
20
|
+
end
|
21
|
+
|
22
|
+
####################
|
23
|
+
# Dependencies #
|
24
|
+
####################
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
#Info
|
29
|
+
def status
|
30
|
+
@exception = env['action_dispatch.exception']
|
31
|
+
@status = ActionDispatch::ExceptionWrapper.new(env, @exception).status_code
|
32
|
+
@response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]
|
33
|
+
end
|
34
|
+
|
35
|
+
#Format
|
36
|
+
def details
|
37
|
+
@details ||= {}.tap do |h|
|
38
|
+
I18n.with_options scope: [:exception, :show, @response], exception_name: @exception.class.name, exception_message: @exception.message do |i18n|
|
39
|
+
h[:name] = i18n.t "#{@exception.class.name.underscore}.title", default: i18n.t(:title, default: @exception.class.name)
|
40
|
+
h[:message] = i18n.t "#{@exception.class.name.underscore}.description", default: i18n.t(:description, default: @exception.message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
helper_method :details
|
45
|
+
|
46
|
+
####################
|
47
|
+
# Layout #
|
48
|
+
####################
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
#Layout
|
53
|
+
def layout_status
|
54
|
+
@status.to_s == "404" ? "application" : "error"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
|
5
|
+
/Info
|
6
|
+
= meta_tags
|
7
|
+
|
8
|
+
/Styling
|
9
|
+
:sass
|
10
|
+
html
|
11
|
+
height: 100%
|
12
|
+
background: #fff url(#{image_path "custom_error_pages/bg.png"}) bottom repeat-x
|
13
|
+
|
14
|
+
body
|
15
|
+
font-family: Helvetica, Arial, Sans-Serif
|
16
|
+
font-size: 14px
|
17
|
+
|
18
|
+
.error_container
|
19
|
+
display: block
|
20
|
+
margin: auto
|
21
|
+
margin: 10% auto 0 auto
|
22
|
+
width: 40%
|
23
|
+
|
24
|
+
.error_container .error
|
25
|
+
display: block
|
26
|
+
text-align: center
|
27
|
+
|
28
|
+
.error_container .error img
|
29
|
+
display: block
|
30
|
+
margin: 0 auto 15px auto
|
31
|
+
|
32
|
+
.error_container .message > *
|
33
|
+
display: block
|
34
|
+
|
35
|
+
.error_container .message strong
|
36
|
+
font-weight: bold
|
37
|
+
color: #f00
|
38
|
+
|
39
|
+
.error_container .contact_info
|
40
|
+
display: block
|
41
|
+
text-align: center
|
42
|
+
margin: 25px 0 0 0
|
43
|
+
|
44
|
+
.error_container .contact_info a
|
45
|
+
display: inline-block
|
46
|
+
margin: 0
|
47
|
+
opacity: 0.4
|
48
|
+
transition: opacity 0.15s ease
|
49
|
+
|
50
|
+
.error_container .contact_info a:hover
|
51
|
+
opacity: 0.8
|
52
|
+
|
53
|
+
|
54
|
+
/Body
|
55
|
+
%body
|
56
|
+
.error_container
|
57
|
+
= yield
|
data/exception_handler.gemspec
CHANGED
@@ -6,21 +6,20 @@ require 'exception_handler/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "exception_handler"
|
8
8
|
spec.version = ExceptionHandler::VERSION
|
9
|
-
spec.authors = ["Richard Peck"
|
10
|
-
spec.email = ["rpeck@frontlineutilities.co.uk"
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
13
|
-
spec.homepage = "http://frontlineutilities.co.uk/
|
9
|
+
spec.authors = ["Richard Peck"]
|
10
|
+
spec.email = ["rpeck@frontlineutilities.co.uk"]
|
11
|
+
spec.summary = %q{Rails gem to show custom error pages in production. Also logs errors in "errors" db if required}
|
12
|
+
spec.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
|
+
spec.homepage = "http://frontlineutilities.co.uk/ror/custom_error_pages"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.metadata = { "source" => "https://github.com/richpeck/exception_handler" }
|
16
15
|
|
17
16
|
spec.files = `git ls-files -z`.split("\x0")
|
18
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
19
|
spec.require_paths = ["lib"]
|
21
20
|
|
22
|
-
spec.post_install_message = "Thank you for installing!"
|
23
|
-
|
24
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
-
spec.add_development_dependency "
|
26
|
-
|
22
|
+
spec.add_development_dependency "rails", "~> 4.0.0"
|
23
|
+
spec.add_development_dependency "haml", "~> 4.0.5"
|
24
|
+
spec.add_development_dependency "sass", "~> 3.3.7"
|
25
|
+
end
|
data/lib/exception_handler.rb
CHANGED
@@ -1,48 +1,20 @@
|
|
1
|
-
|
1
|
+
###########################################
|
2
2
|
|
3
3
|
require "action_dispatch"
|
4
|
+
|
4
5
|
require "exception_handler/version"
|
5
6
|
require "exception_handler/parser"
|
6
7
|
|
7
|
-
|
8
|
+
###########################################
|
8
9
|
|
9
10
|
module ExceptionHandler
|
10
11
|
|
11
|
-
#
|
12
|
-
class
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#DB / Email
|
18
|
-
class Message
|
19
|
-
|
20
|
-
# Init
|
21
|
-
def initialize(app)
|
22
|
-
@app = app
|
23
|
-
end
|
24
|
-
|
25
|
-
#Error
|
26
|
-
def call(env)
|
27
|
-
@app.call(env)
|
28
|
-
|
29
|
-
rescue Exception => exception
|
30
|
-
request = ActionDispatch::Request.new(env)
|
31
|
-
controller = env['action_controller.instance']
|
32
|
-
|
33
|
-
ErrorHandler::Parser.new(exception, request, controller).save unless self.ignore?(exception, request)
|
34
|
-
raise exception
|
35
|
-
end
|
36
|
-
|
37
|
-
#Ignore
|
38
|
-
def ignore?(exception, request, ignored = {})
|
39
|
-
ignored[:errors] = [ActionController::RoutingError, AbstractController::ActionNotFound, ActiveRecord::RecordNotFound]
|
40
|
-
ignored[:bots] = /\b(Baidu|Gigabot|Googlebot|libwww-per|lwp-trivial|msnbot|SiteUptime|Slurp|Wordpress|ZIBB|ZyBorg|Yandex|Jyxobot|Huaweisymantecspider|ApptusBot)\b/i
|
41
|
-
|
42
|
-
return true if ignored[:errors].include?(exception.class) && request.referer.blank?
|
43
|
-
return true if request.user_agent =~ ignored[:bots]
|
12
|
+
#Exception Handler
|
13
|
+
class Exceptions < Rails::Engine
|
14
|
+
initializer "exception_handler.configure_rails_initialization" do |app|
|
15
|
+
app.config.middleware.use "ExceptionHandler::Message" #Parser
|
16
|
+
app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionController.action(:show).call(env) } #Pages
|
44
17
|
end
|
45
|
-
|
46
18
|
end
|
47
19
|
|
48
20
|
end
|
@@ -1,4 +1,37 @@
|
|
1
|
-
module
|
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
|
2
35
|
class Parser
|
3
36
|
|
4
37
|
#Init
|
@@ -9,7 +42,7 @@ module ErrorHandler
|
|
9
42
|
#Save
|
10
43
|
def save
|
11
44
|
ActiveRecord::Base.logger.silence do
|
12
|
-
Error.create(relevant_info)
|
45
|
+
#ExceptionHandler::Error.create(relevant_info)
|
13
46
|
end
|
14
47
|
log(relevant_info)
|
15
48
|
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module ExceptionHandler
|
2
|
-
VERSION = "0.0
|
3
|
-
end
|
2
|
+
VERSION = "0.2.0"
|
3
|
+
end
|
Binary file
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exception_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Peck
|
8
|
-
- Joe Hilton
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-28 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
@@ -26,43 +25,74 @@ dependencies:
|
|
26
25
|
- !ruby/object:Gem::Version
|
27
26
|
version: '1.6'
|
28
27
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
28
|
+
name: rails
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
31
30
|
requirements:
|
32
|
-
- -
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: haml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
33
46
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
47
|
+
version: 4.0.5
|
35
48
|
type: :development
|
36
49
|
prerelease: false
|
37
50
|
version_requirements: !ruby/object:Gem::Requirement
|
38
51
|
requirements:
|
39
|
-
- -
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sass
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.3.7
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
40
67
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
42
|
-
description:
|
43
|
-
|
68
|
+
version: 3.3.7
|
69
|
+
description: Rails gem to create custom error pages. Captures exceptions using "exception_app"
|
70
|
+
callback, routing to "Exception" controller, rendering the view as required.
|
44
71
|
email:
|
45
72
|
- rpeck@frontlineutilities.co.uk
|
46
|
-
- jhilton@frontlineutilities.co.uk
|
47
73
|
executables: []
|
48
74
|
extensions: []
|
49
75
|
extra_rdoc_files: []
|
50
76
|
files:
|
51
77
|
- .gitignore
|
78
|
+
- .travis.yml
|
52
79
|
- Gemfile
|
53
80
|
- LICENSE.txt
|
54
81
|
- README.md
|
55
82
|
- Rakefile
|
83
|
+
- app/controllers/exception_handler/exception_controller.rb
|
84
|
+
- app/views/exception_handler/exception/show.html.haml
|
85
|
+
- app/views/layouts/error.html.haml
|
56
86
|
- exception_handler.gemspec
|
57
87
|
- lib/exception_handler.rb
|
58
88
|
- lib/exception_handler/parser.rb
|
59
89
|
- lib/exception_handler/version.rb
|
60
|
-
|
90
|
+
- vendor/assets/images/exception_handler/bg.png
|
91
|
+
homepage: http://frontlineutilities.co.uk/ror/custom_error_pages
|
61
92
|
licenses:
|
62
93
|
- MIT
|
63
|
-
metadata:
|
64
|
-
|
65
|
-
post_install_message: Thank you for installing!
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
66
96
|
rdoc_options: []
|
67
97
|
require_paths:
|
68
98
|
- lib
|
@@ -81,5 +111,6 @@ rubyforge_project:
|
|
81
111
|
rubygems_version: 2.0.14
|
82
112
|
signing_key:
|
83
113
|
specification_version: 4
|
84
|
-
summary:
|
114
|
+
summary: Rails gem to show custom error pages in production. Also logs errors in "errors"
|
115
|
+
db if required
|
85
116
|
test_files: []
|