exception_handler 0.7.6.0 → 0.7.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 +40 -33
- data/.slugignore +7 -7
- data/.travis.yml +5 -5
- data/Gemfile +13 -13
- data/README.md +436 -436
- data/Rakefile +7 -7
- data/app/assets/stylesheets/exception_handler.css.erb +18 -18
- data/app/assets/stylesheets/styles/_base.css.erb +35 -35
- data/app/assets/stylesheets/styles/_exception.css.erb +105 -105
- data/app/assets/stylesheets/styles/_footer.css.erb +24 -24
- data/app/assets/stylesheets/styles/_responsive.css +5 -5
- data/app/controllers/exception_handler/exceptions_controller.rb +59 -59
- data/app/mailers/exception_handler/exception_mailer.rb +17 -17
- data/app/models/exception_handler/exception.rb +199 -191
- data/app/views/exception_handler/exceptions/show.html.erb +3 -3
- data/app/views/exception_handler/mailers/layout.haml +8 -8
- data/app/views/exception_handler/mailers/layout.text.erb +1 -1
- data/app/views/exception_handler/mailers/new_exception.erb +4 -4
- data/app/views/layouts/exception.html.erb +27 -27
- data/config/locales/exception_handler.en.yml +28 -28
- data/db/migrate/000000_create_errors.rb +34 -34
- data/exception_handler.gemspec +62 -80
- data/lib/exception_handler.rb +55 -45
- data/lib/exception_handler/config.rb +116 -104
- data/lib/exception_handler/engine.rb +70 -61
- data/lib/exception_handler/version.rb +25 -0
- data/lib/generators/exception_handler/views_generator.rb +33 -33
- metadata +7 -71
- data/.gitattributes +0 -1
- data/.rspec +0 -4
- data/LICENSE.txt +0 -22
- data/spec/database.yml +0 -3
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/config/manifest.js +0 -4
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/javascripts/cable.coffee +0 -11
- data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/channels/application_cable/channel.rb +0 -5
- data/spec/dummy/app/channels/application_cable/connection.rb +0 -5
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/jobs/application_job.rb +0 -2
- data/spec/dummy/app/mailers/application_mailer.rb +0 -4
- data/spec/dummy/app/models/application_record.rb +0 -3
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -15
- data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
- data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/bin/setup +0 -34
- data/spec/dummy/bin/update +0 -29
- data/spec/dummy/config.ru +0 -8
- data/spec/dummy/config/application.rb +0 -21
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/cable.yml +0 -10
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -62
- data/spec/dummy/config/environments/production.rb +0 -87
- data/spec/dummy/config/environments/test.rb +0 -42
- data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +0 -6
- data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -6
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/callback_terminator.rb +0 -6
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -5
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/per_form_csrf_tokens.rb +0 -4
- data/spec/dummy/config/initializers/request_forgery_protection.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/puma.rb +0 -47
- data/spec/dummy/config/routes.rb +0 -6
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- 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 +0 -22
- data/spec/exception_handler/exception_controller_spec.rb +0 -18
- data/spec/spec_helper.rb +0 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 148c46f79b5ee16ca3c48ec3e9bffc41624ec964
|
4
|
+
data.tar.gz: 25c4c163fbbf6fbc0e11622150b9384f853f3c23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 592424a51d78607fd8ca707e573f98fe5586ea55920ca39fcc598228cece073f2c25002dd57ee09b17233096a78bde8ece09f165309d99d071c44e8dc654a6d7
|
7
|
+
data.tar.gz: d65c120bf893e025fa1f68808a2feb1d403b7f3e036088e0ebb253008c67861f4e50f5e24ac12b3bd812e910cb113ec4b1cf37ae9af52ff9285196e5937a373f
|
data/.gitignore
CHANGED
@@ -1,33 +1,40 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
.bundle
|
4
|
-
.config
|
5
|
-
.yardoc
|
6
|
-
Gemfile.lock
|
7
|
-
InstalledFiles
|
8
|
-
_yardoc
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
*.bundle
|
19
|
-
*.so
|
20
|
-
*.o
|
21
|
-
*.a
|
22
|
-
mkmf.log
|
23
|
-
*.tmp
|
24
|
-
|
25
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
*.tmp
|
24
|
+
|
25
|
+
# Desktop INI (Windows)
|
26
|
+
desktop.ini
|
27
|
+
|
28
|
+
# Git BFG
|
29
|
+
.git.bfg-report
|
30
|
+
.git.bfg-report/2017-06-29/07-53-00
|
31
|
+
|
32
|
+
# http://stackoverflow.com/questions/8865848/comments-in-gitignore
|
33
|
+
# https://gist.github.com/danielpcox/4636520
|
34
|
+
|
35
|
+
log/*.log
|
36
|
+
pkg/
|
37
|
+
spec/dummy/db/*.sqlite3
|
38
|
+
spec/dummy/log/*.log
|
39
|
+
spec/dummy/tmp/
|
40
|
+
spec/dummy/.sass-cache
|
data/.slugignore
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# Ignore art files
|
2
|
-
# https://devcenter.heroku.com/articles/slug-compiler#ignoring-files-with-slugignore
|
3
|
-
*.psd
|
4
|
-
*.pdf
|
5
|
-
/test
|
6
|
-
/spec
|
7
|
-
/readme
|
1
|
+
# Ignore art files
|
2
|
+
# https://devcenter.heroku.com/articles/slug-compiler#ignoring-files-with-slugignore
|
3
|
+
*.psd
|
4
|
+
*.pdf
|
5
|
+
/test
|
6
|
+
/spec
|
7
|
+
/readme
|
data/.travis.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
rvm:
|
2
|
-
- 2.2.4
|
3
|
-
- 2.3.2
|
4
|
-
- 2.4.0
|
5
|
-
- ruby-head
|
1
|
+
rvm:
|
2
|
+
- 2.2.4
|
3
|
+
- 2.3.2
|
4
|
+
- 2.4.0
|
5
|
+
- ruby-head
|
data/Gemfile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in custom_error_pages.gemspec
|
4
|
-
gemspec
|
5
|
-
|
6
|
-
###########################################
|
7
|
-
|
8
|
-
#For Testing
|
9
|
-
group :test do
|
10
|
-
gem 'coveralls', require: false
|
11
|
-
end
|
12
|
-
|
13
|
-
###########################################
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in custom_error_pages.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
###########################################
|
7
|
+
|
8
|
+
#For Testing
|
9
|
+
group :test do
|
10
|
+
gem 'coveralls', require: false
|
11
|
+
end
|
12
|
+
|
13
|
+
###########################################
|
data/README.md
CHANGED
@@ -1,436 +1,436 @@
|
|
1
|
-
![Exception Handler](readme/title.jpg "Exception Handler Logo")
|
2
|
-
|
3
|
-
<p align="center">
|
4
|
-
<font size="4"><strong>Custom 404 & 500 production error pages for Rails 4 & 5.</font></strong>
|
5
|
-
</p>
|
6
|
-
|
7
|
-
<p align="center">
|
8
|
-
<a href="http://badge.fury.io/rb/exception_handler"><img src="https://badge.fury.io/rb/exception_handler.svg" align="absmiddle"></a>
|
9
|
-
<a href="http://rubygems.org/gems/exception_handler"><img src="http://ruby-gem-downloads-badge.herokuapp.com/exception_handler/0.5.1?type=total&color=brightgreen" align="absmiddle" /></a>
|
10
|
-
<a href="https://codeclimate.com/github/richpeck/exception_handler"><img src="https://codeclimate.com/github/richpeck/exception_handler/badges/gpa.svg" align="absmiddle"/></a>
|
11
|
-
<a href="https://gemnasium.com/richpeck/exception_handler"><img src="https://gemnasium.com/richpeck/exception_handler.svg" align="absmiddle"></a>
|
12
|
-
<a href='https://coveralls.io/github/richpeck/exception_handler?branch=master'><img src='https://coveralls.io/repos/github/richpeck/exception_handler/badge.svg?branch=master' alt='Coverage Status' align="absmiddle" /></a>
|
13
|
-
<a href="https://travis-ci.org/richpeck/exception_handler"><img src="https://travis-ci.org/richpeck/exception_handler.svg?branch=master" align="absmiddle"></a>
|
14
|
-
</p>
|
15
|
-
|
16
|
-
<p align="center">
|
17
|
-
<strong><a href="#install">Install</a></strong> → <strong><a href="#config">Setup</a></strong> → <strong><a href="#support">Support</a></strong>
|
18
|
-
</p>
|
19
|
-
|
20
|
-
---
|
21
|
-
|
22
|
-
<p align="center">
|
23
|
-
<img src="readme/version.jpg" /><br/>
|
24
|
-
</p>
|
25
|
-
|
26
|
-
<p align="center">
|
27
|
-
<img src="readme/check.png" height="22" title="Fully Responsive" align="absmiddle" /> <strong>Responsive</strong>
|
28
|
-
<img src="readme/check.png" height="22" title="Branded Error Pages" align="absmiddle" /> <strong>Branded Error Pages</strong>
|
29
|
-
<img src="readme/check.png" height="22" title="Middleware Exception Handling" align="absmiddle" /> <strong>Middleware Exception Handling</strong>
|
30
|
-
<img src="readme/check.png" height="22" title="Keep Users Informed" align="absmiddle" /> <strong>Fully Customizable</strong>
|
31
|
-
</p>
|
32
|
-
|
33
|
-
<p align="center">
|
34
|
-
<img src="readme/branded/1.jpg" width="425" title="Fully Branded Error Pages" /> <img src="readme/branded/2.jpg" width="425" title="Fully Branded Error Pages" />
|
35
|
-
<img src="readme/branded/3.jpg" width="425" title="Fully Branded Error Pages" /> <img src="readme/branded/4.jpg" width="425" title="Fully Branded Error Pages" />
|
36
|
-
</p>
|
37
|
-
|
38
|
-
---
|
39
|
-
|
40
|
-
<p align="center">
|
41
|
-
<img src="readme/rails.jpg" title="Version 0.7.5 Released Early 2017" />
|
42
|
-
</p>
|
43
|
-
|
44
|
-
---
|
45
|
-
|
46
|
-
<p align="center">
|
47
|
-
<img src="readme/titles/rails5.png" title="Fully Rails 5 Compatible" width="625" />
|
48
|
-
</p>
|
49
|
-
|
50
|
-
<p align="center">
|
51
|
-
<img src="readme/check_02.png" height="22" title="New Controller" align="absmiddle" /> <strong align="absmiddle">New Controller</strong>
|
52
|
-
<img src="readme/check_02.png" height="22" title="New Middleware" align="absmiddle" /> <strong align="absmiddle">New Middleware</strong>
|
53
|
-
<img src="readme/check_02.png" height="22" title="Full Test Suite" align="absmiddle" /> <strong align="absmiddle">Full Test Suite</strong>
|
54
|
-
<img src="readme/check_02.png" height="22" title="Rails 4 & 5 Compatible" align="absmiddle" /> <strong align="absmiddle">Fully Rails 4 & 5 Compatible</strong>
|
55
|
-
</p>
|
56
|
-
|
57
|
-
Brand new `controller` & `middleware` have made **`ExceptionHandler`** even more powerful & efficient. Now you can use `ExceptionHandler` with a [single click](#install) → **plug and play** custom exception pages:
|
58
|
-
|
59
|
-
<p align="center">
|
60
|
-
<br />
|
61
|
-
<img src="readme/400.png" title="400 Errors" width="430" />
|
62
|
-
<img src="readme/500.png" title="500 Errors" width="430" />
|
63
|
-
</p>
|
64
|
-
|
65
|
-
<p align="center">For over 3 years, <strong>ExceptionHandler</strong> has provided production-level <strong>Rails</strong> exception handling for <strong>4xx</strong> and <strong>5xx</strong> errors:</p>
|
66
|
-
|
67
|
-
![HTTP Error Codes][http_codes]
|
68
|
-
|
69
|
-
Since **browsers only read `4xx` & `5xx` error codes**, all Rails exceptions have to be inferred. Thus, `ExceptionHandler` simply has to manage how the `4xx` / `5xx` errors are passed to the browser.
|
70
|
-
|
71
|
-
Unlike other gems, **`ExceptionHandler` uses a custom [`controller`](app/controllers/exception_handler/exceptions_controller.rb) to build an [`@exception`](app/models/exception_handler/exception.rb) object**. This allows us to save the exception, email it or do anything else we may need. The gem has already been a massive success and we continue to actively maintain it.
|
72
|
-
|
73
|
-
Now you can try for yourself ...
|
74
|
-
|
75
|
-
|
76
|
-
----
|
77
|
-
|
78
|
-
<p align="center">
|
79
|
-
<br />
|
80
|
-
<img src="readme/titles/middleware.png" title="Middleware-Powered Exceptions" width="400" />
|
81
|
-
</p>
|
82
|
-
|
83
|
-
The secret lies in [**`config.exceptions_app`**][exception_app] ↴
|
84
|
-
|
85
|
-
> **`config.exceptions_app`** sets the exceptions application invoked by the **`ShowException`** middleware when an exception happens. Defaults to **`ActionDispatch::PublicExceptions.new(Rails.public_path)`**
|
86
|
-
|
87
|
-
![Exceptions handled by the ActiveDispatch::ShowExceptions Middleware][middleware]
|
88
|
-
|
89
|
-
Each time an exception is raised, [`ShowExceptions`][show_exception] takes the request and forwards it to `config.exceptions_app`. This is expected to return a response - allowing us to inject a [`controller`](app/controllers/exception_handler/exceptions_controller.rb):
|
90
|
-
|
91
|
-
![config.exceptions_app - The key to all Rails exceptions][exceptions_app]
|
92
|
-
|
93
|
-
Because our callback maintains the request, we are able to do whatever we need before serving a response. This is a **major** advantage over the "default" (routes). The routes invokes Rails twice and does not persist the request.
|
94
|
-
|
95
|
-
**`ExceptionHandler` is the only gem to provide middleware-powered exception handling.** It populates our custom `view` with details, giving us the ability to **maintain branding** when exceptions are raised:
|
96
|
-
|
97
|
-
![Exceptions handled by the ActiveDispatch::ShowExceptions Middleware][middleware]
|
98
|
-
|
99
|
-
**`ExceptionHandler` is the most EFFECTIVE and EFFICIENT gem to handle exceptions in Rails**.
|
100
|
-
|
101
|
-
Once invoked, its `model`, `controller` and `views` work together to serve the best responses to Rails errors ...
|
102
|
-
|
103
|
-
----------
|
104
|
-
|
105
|
-
<p align="center" id="install">
|
106
|
-
<br />
|
107
|
-
<img src="readme/titles/install.png" title="1 Click Install for ExceptionHandler 0.7.0 on Rails 5" width="400" />
|
108
|
-
<br />
|
109
|
-
<strong>Custom Rails Error Pages - ZERO configuration needed:</strong>
|
110
|
-
<br />
|
111
|
-
</p>
|
112
|
-
|
113
|
-
<p align="center">
|
114
|
-
<a href="http://rubygems.org/gems/exception_handler"><img src="readme/gem.jpg" /></a> <a href="http://rubygems.org/gems/exception_handler"><img src="readme/gemfile.jpg" /></a>
|
115
|
-
</p>
|
116
|
-
|
117
|
-
|
118
|
-
<p align="center">
|
119
|
-
You can install it from the <strong>CLI</strong> or <strong>Gemfile</strong> - it will AUTOMATICALLY run in <strong>production</strong>.
|
120
|
-
<br />
|
121
|
-
<strong>↓ To run in development, use <a href="#dev-mode">dev mode</a> ↓</strong>
|
122
|
-
</p>
|
123
|
-
|
124
|
-
---
|
125
|
-
|
126
|
-
<p align="center">
|
127
|
-
If you want to set it up your way, you can use these features...
|
128
|
-
</p>
|
129
|
-
|
130
|
-
<p align="center">
|
131
|
-
<a href="#config"><img src="readme/titles/icons/config.png" alt="Cinfiguration Options" align="absmiddle" height="24" /> Config</a> <a href="#dev-mode" title="Dev Mode"><img src="readme/titles/icons/dev.png" alt="Dev" align="absmiddle" height="24" /> Dev</a> <a href="#database"><img src="readme/titles/icons/database.png" alt="Database" align="absmiddle" height="24" /> Database</a> <a href="#email"><img src="readme/titles/icons/email.png" alt="Email" align="absmiddle" height="24" /> Email</a> <a href="#views"><img src="readme/titles/icons/views.png" alt="Views" align="absmiddle" height="24" /> Views</a> <a href="#locales"><img src="readme/titles/icons/locales.png" alt="Locales" align="absmiddle" height="20" /> Locales</a> <a href="#custom-exceptions"><img src="readme/titles/icons/custom.png" alt="Custom Exceptions" align="absmiddle" height="18" /> Custom Exceptions</a> <a href="#generators"><img src="readme/titles/icons/generators.png" alt="Generators" align="absmiddle" height="24" /> Generators</a>
|
132
|
-
</p>
|
133
|
-
|
134
|
-
----
|
135
|
-
|
136
|
-
## Config
|
137
|
-
|
138
|
-
**From [`0.4.7`](https://github.com/richpeck/exception_handler/releases/tag/0.4.6), `ExceptionHandler` manages its [config](lib/exception_handler/config.rb#L45) from the central Rails `config` hash:**
|
139
|
-
|
140
|
-
[![config][config]](lib/exception_handler/config.rb#L45)
|
141
|
-
|
142
|
-
If you're using an [`engine`](http://guides.rubyonrails.org/engines.html), you don't need to use an `initializer`:
|
143
|
-
|
144
|
-
# lib/engine.rb
|
145
|
-
module YourModule
|
146
|
-
class Engine < Rails::Engine
|
147
|
-
|
148
|
-
# => ExceptionHandler
|
149
|
-
# => Works in and out of an initializer
|
150
|
-
config.exception_handler = {
|
151
|
-
dev: false,
|
152
|
-
db: true
|
153
|
-
}
|
154
|
-
end
|
155
|
-
|
156
|
-
end
|
157
|
-
|
158
|
-
You only need to provide the inputs you want, for example:
|
159
|
-
|
160
|
-
# config/application.rb
|
161
|
-
config.exception_handler = { dev: true }
|
162
|
-
|
163
|
-
# config/environments/production.rb
|
164
|
-
config.exception_handler = { social: { fusion: "flutils" }}
|
165
|
-
|
166
|
-
----
|
167
|
-
|
168
|
-
## Dev Mode
|
169
|
-
|
170
|
-
**To enable `ExceptionHandler` in dev, enable the [`dev`](lib/exception_handler/config.rb#L38) option:**
|
171
|
-
|
172
|
-
![Dev][dev_mode]
|
173
|
-
|
174
|
-
This disables [`config.consider_all_requests_local`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration), making Rails behave as it would in production:
|
175
|
-
|
176
|
-
![Dev][dev_img]
|
177
|
-
|
178
|
-
----
|
179
|
-
|
180
|
-
## Database
|
181
|
-
|
182
|
-
**We also have `ActiveRecord` integration.**
|
183
|
-
|
184
|
-
If you want to save your exceptions to `db`, you need to enable the `db` config option:
|
185
|
-
|
186
|
-
# config/application.rb
|
187
|
-
config.exception_handler = {
|
188
|
-
db: true
|
189
|
-
}
|
190
|
-
|
191
|
-
This enables `ActiveRecord::Base` on the [`Exception`](app/models/exception_handler/exception.rb) class, allowing us to save to the database.
|
192
|
-
|
193
|
-
In order for this to work, your db needs the correct table.
|
194
|
-
|
195
|
-
To do this, once you've enabled the option, run `rails db:migrate` from your console. Our new [`migration system`](https://github.com/richpeck/exception_handler/tree/readme#migrations) will automatically run the migration.
|
196
|
-
|
197
|
-
---
|
198
|
-
|
199
|
-
## Email
|
200
|
-
|
201
|
-
**`ExceptionHandler` also now sends email notifications.**
|
202
|
-
|
203
|
-
If you want to receive emails whenever your application raises an error, you can do so by adding your email to the config:
|
204
|
-
|
205
|
-
# config/application.rb
|
206
|
-
config.exception_handler = {
|
207
|
-
email: "your@email.com"
|
208
|
-
}
|
209
|
-
|
210
|
-
> **Please Note** this requires [`ActionMailer`](http://guides.rubyonrails.org/action_mailer_basics.html). If you don't have any outbound SMTP server, [`SendGrid`](http://sendgrid.com) is free.
|
211
|
-
|
212
|
-
[Full tutorial here](https://github.com/richpeck/exception_handler/wiki/2-Email)
|
213
|
-
|
214
|
-
---
|
215
|
-
|
216
|
-
## Views
|
217
|
-
|
218
|
-
**From [`0.7.0`](#070), we overhauled the view system:**
|
219
|
-
|
220
|
-
![View][view_img]
|
221
|
-
|
222
|
-
[Wiew](app/views/exception_handler/exceptions/show.html.erb) is modular - `@exception` populated with [`locales`](#locales).
|
223
|
-
|
224
|
-
---
|
225
|
-
|
226
|
-
## Locales
|
227
|
-
|
228
|
-
**[`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5) introduced [locales](config/locales/exception_handler.yml) ...**
|
229
|
-
|
230
|
-
[[ locales ]]
|
231
|
-
|
232
|
-
The `ExceptionHandler` view is populated by [`@exception.description`](app/models/exception_handler/exception.rb#L121), which pulls from the `locales`.
|
233
|
-
|
234
|
-
If you want custom messages, you need the following. The key is defined by the HTTP [`status_code`](https://github.com/rack/rack/blob/1.5.2/lib/rack/utils.rb#L544)
|
235
|
-
|
236
|
-
# config/locales/en.yml
|
237
|
-
en:
|
238
|
-
exception_handler:
|
239
|
-
not_found: "Your message here"
|
240
|
-
unauthorized: "You need to login to continue"
|
241
|
-
internal_server_error: "This is a test to show the %{status} of the error"
|
242
|
-
|
243
|
-
You get access to `%{message}` and `%{status}`, both inferring from `@exception`.
|
244
|
-
|
245
|
-
---
|
246
|
-
|
247
|
-
## Layout
|
248
|
-
|
249
|
-
**The `layout` has also been improved ↴**
|
250
|
-
|
251
|
-
![Layout][layout_img]
|
252
|
-
|
253
|
-
We now assign layouts to the **status code** of the response:
|
254
|
-
|
255
|
-
![Layout][layouts_img]
|
256
|
-
|
257
|
-
By default, `5xx` errors are shown with our [`exception` layout][layout] - this can be overridden by changing the `config` to use a layout of your choice. If you want to inherit the `ApplicationController` layout, assign the codes to `nil`.
|
258
|
-
|
259
|
-
---
|
260
|
-
|
261
|
-
|
262
|
-
## Custom Exceptions
|
263
|
-
|
264
|
-
**Custom Exceptions also supported in [`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)**
|
265
|
-
|
266
|
-
Rails handles this for us - [**`config.action_dispatch.rescue_responses`**][rescue_responses] ↴
|
267
|
-
|
268
|
-
![ActionDispatch][config.action_dispatch.rescue_responses]
|
269
|
-
|
270
|
-
You need to add to the `rescue_responses` hash in your app's config (mapped to [`status codes`](https://github.com/rack/rack/blob/1.5.2/lib/rack/utils.rb#L544)):
|
271
|
-
|
272
|
-
# config/application.rb
|
273
|
-
config.action_dispatch.rescue_responses["ActionController::YourError"] = :bad_request
|
274
|
-
|
275
|
-
Because `HTTP` can only process `4xx` / `5xx` errors, if `Rails` raises an exception, it needs to assign one of the error status codes. **Default** is [`internal_server_error`](https://github.com/rack/rack/blob/1.5.2/lib/rack/utils.rb#L595) - if you'd prefer your app to just return `500` errors for your custom exception, you don't need to explicitly declare them.
|
276
|
-
|
277
|
-
---
|
278
|
-
|
279
|
-
## Generators
|
280
|
-
|
281
|
-
**You can generate `ExceptionHandler` into your own application.**
|
282
|
-
|
283
|
-
[[ Generator ]]
|
284
|
-
|
285
|
-
The following commands will copy the directories...
|
286
|
-
|
287
|
-
rails g exception_handler:views
|
288
|
-
rails g exception_handler:views -v views
|
289
|
-
rails g exception_handler:views -v controllers
|
290
|
-
rails g exception_handler:views -v models
|
291
|
-
rails g exception_handler:views -v assets
|
292
|
-
rails g exception_handler:views -v views controllers models assets
|
293
|
-
|
294
|
-
If you don't include any switches, this will copy **all** the folders put into your app.
|
295
|
-
|
296
|
-
Each switch defines which folders you want (EG `-v views` will only copy `views` dir).
|
297
|
-
|
298
|
-
---
|
299
|
-
|
300
|
-
### Migrations (deprecated)
|
301
|
-
|
302
|
-
**From [`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5), the `migration` generator has been removed in favour of our own [migration system](lib/exception_handler/engine.rb#L58)**
|
303
|
-
|
304
|
-
You don't need to generate a migration any more.
|
305
|
-
|
306
|
-
If you set the `db` option in config, run `rails db:migrate` and the migration will be run.
|
307
|
-
|
308
|
-
To rollback, use the following:
|
309
|
-
|
310
|
-
rails db:migrate:down VERSION=000000
|
311
|
-
|
312
|
-
> The drawback to this is that if you remove `ExceptionHandler` before you rollback the migration, it won't exist anymore. You can **only** fire the `rollback` when you have `ExceptionHandler` installed.
|
313
|
-
|
314
|
-
---
|
315
|
-
|
316
|
-
## Support
|
317
|
-
|
318
|
-
[Issues](https://github.com/richpeck/exception_handler/issues)
|
319
|
-
|
320
|
-
---
|
321
|
-
|
322
|
-
## Changelog
|
323
|
-
|
324
|
-
### [0.7.5](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)
|
325
|
-
- [x] [HTTP status layouts](#layouts)
|
326
|
-
|
327
|
-
### [0.7.0](https://github.com/richpeck/exception_handler/releases/tag/0.7.0)
|
328
|
-
- [x] Wildcard mime types
|
329
|
-
- [x] [Custom exceptions](#custom_exceptions)
|
330
|
-
- [x] Test suite integration
|
331
|
-
- [x] [Email](#email)
|
332
|
-
- [x] [Model backend](#database)
|
333
|
-
- [x] Sprockets 4+
|
334
|
-
- [x] New layout
|
335
|
-
- [x] Readme / wiki overhaul
|
336
|
-
|
337
|
-
### [0.6.5](https://github.com/richpeck/exception_handler/releases/tag/0.6.5)
|
338
|
-
- [x] Streamlined interface
|
339
|
-
- [x] ActiveRecord / Middleware overhaul
|
340
|
-
- [x] Supports Sprockets 4+ ([`manifest.js`](http://eileencodes.com/posts/the-sprockets-4-manifest/))
|
341
|
-
- [x] Email integration
|
342
|
-
- [x] Asset overhaul & improvement
|
343
|
-
- [x] Removed dependencies
|
344
|
-
|
345
|
-
### [0.5.0](https://github.com/richpeck/exception_handler/releases/tag/0.5.0)
|
346
|
-
- [x] Locales
|
347
|
-
- [x] Email notifications
|
348
|
-
- [x] Full test suite
|
349
|
-
- [x] Rails 4.2 & Rails 5.0 native ([`request.env`](https://github.com/rails/rails/commit/05934d24aff62d66fc62621aa38dae6456e276be) fix)
|
350
|
-
- [x] Controller fixed
|
351
|
-
- [x] `DB` fixed
|
352
|
-
- [x] Legacy initializer support ([more](https://github.com/richpeck/exception_handler/wiki/1-Setup))
|
353
|
-
- [x] Rails asset management improvement
|
354
|
-
- [x] Reduced gem file size
|
355
|
-
|
356
|
-
### [0.4.7](https://github.com/richpeck/exception_handler/releases/tag/0.4.6)
|
357
|
-
- [x] New config system
|
358
|
-
- [x] Fixed controller layout issues
|
359
|
-
- [x] Streamlined middleware
|
360
|
-
- [x] New layout & interface
|
361
|
-
|
362
|
-
----
|
363
|
-
|
364
|
-
[![404 + 500 Errors][banner]][rubygems]
|
365
|
-
|
366
|
-
<p align="center">
|
367
|
-
<strong><a href="#">ExceptionHandler</a> is now the leading custom error pages gem for Rails.</strong>
|
368
|
-
<br />
|
369
|
-
No other gem is as simple or effective at providing beautiful exception pages in production.
|
370
|
-
</p>
|
371
|
-
|
372
|
-
<p align="center">
|
373
|
-
<a href="http://badge.fury.io/rb/exception_handler"><img src="https://badge.fury.io/rb/exception_handler.svg" align="absmiddle"></a>
|
374
|
-
<a href="http://rubygems.org/gems/exception_handler"><img src="http://ruby-gem-downloads-badge.herokuapp.com/exception_handler/0.5.1?type=total&color=brightgreen" align="absmiddle" /></a>
|
375
|
-
<a href="https://codeclimate.com/github/richpeck/exception_handler"><img src="https://codeclimate.com/github/richpeck/exception_handler/badges/gpa.svg" align="absmiddle"/></a>
|
376
|
-
<a href="https://gemnasium.com/richpeck/exception_handler"><img src="https://gemnasium.com/richpeck/exception_handler.svg" align="absmiddle"></a>
|
377
|
-
<a href='https://coveralls.io/github/richpeck/exception_handler?branch=master'><img src='https://coveralls.io/repos/github/richpeck/exception_handler/badge.svg?branch=master' alt='Coverage Status' align="absmiddle" /></a>
|
378
|
-
<a href="https://travis-ci.org/richpeck/exception_handler"><img src="https://travis-ci.org/richpeck/exception_handler.svg?branch=master" align="absmiddle"></a>
|
379
|
-
</p>
|
380
|
-
|
381
|
-
<p align="center">
|
382
|
-
<strong><a href="https://rubygems.org/gems/exception_handler">Download Here</a></strong>
|
383
|
-
</p>
|
384
|
-
|
385
|
-
----------
|
386
|
-
|
387
|
-
:copyright: <a href="http://www.frontlineutilities.co.uk" align="absmiddle" ><img src="readme/fl.jpg" height="22" align="absmiddle" /></a> <a href="http://stackoverflow.com/users/1143732/richard-peck?tab=profile" align="absmiddle" ><img src="https://avatars0.githubusercontent.com/u/1104431" height="22" align="absmiddle" /></a>
|
388
|
-
|
389
|
-
<!-- ################################### -->
|
390
|
-
<!-- ################################### -->
|
391
|
-
|
392
|
-
<!-- Refs -->
|
393
|
-
<!-- Comments http://stackoverflow.com/a/20885980/1143732 -->
|
394
|
-
<!-- Images https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#images -->
|
395
|
-
|
396
|
-
<!-- Images -->
|
397
|
-
[dev_mode]: readme/dev_mode.jpg
|
398
|
-
[dev_img]: readme/dev.png
|
399
|
-
[layouts_img]: readme/layouts.jpg
|
400
|
-
[layout_img]: readme/layout.png
|
401
|
-
[view_img]: readme/view.jpg
|
402
|
-
[http_codes]: readme/http_codes.png
|
403
|
-
[config]: readme/config.jpg
|
404
|
-
[config.action_dispatch.rescue_responses]: readme/config.action_dispatch.rescue_responses.jpg
|
405
|
-
[banner]: readme/banner.jpg
|
406
|
-
[gem]: readme/gem.jpg
|
407
|
-
[gemfile]: readme/gemfile.jpg
|
408
|
-
[middleware]: readme/middleware.jpg
|
409
|
-
[exceptions_app]: readme/exceptions_app.jpg
|
410
|
-
[view]: readme/titles/view.jpg
|
411
|
-
[dev]: readme/titles/dev.jpg
|
412
|
-
[db]: readme/titles/db.png
|
413
|
-
[support]: readme/titles/support.png "Support"
|
414
|
-
[changelog]: readme/titles/changelog.png "Changelog"
|
415
|
-
[contribution]: readme/titles/contributions.png "Contributions"
|
416
|
-
[fl]: readme/fl.jpg "Frontline Utilities LTD"
|
417
|
-
[profile]: https://avatars0.githubusercontent.com/u/1104431 "R Peck"
|
418
|
-
|
419
|
-
<!-- Links -->
|
420
|
-
[better_errors]: https://github.com/charliesome/better_errors
|
421
|
-
[layout]: app/views/layouts/exception.html.erb
|
422
|
-
[status_codes]: http://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option
|
423
|
-
[stackoverflow]: http://stackoverflow.com/questions/ask?tags=ruby-on-rails+exception-handler
|
424
|
-
[rescue_responses]: http://guides.rubyonrails.org/configuring.html#configuring-action-dispatch
|
425
|
-
[latest]: https://github.com/richpeck/exception_handler/releases/latest
|
426
|
-
[show_exception]: https://github.com/rails/rails/blob/4-0-stable/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
|
427
|
-
[exception_app]: http://guides.rubyonrails.org/configuring.html#rails-general-configuration
|
428
|
-
[rubygems]: http://rubygems.org/gems/exception_handler
|
429
|
-
[frontlineutilities.co.uk]: http://www.frontlineutilities.co.uk
|
430
|
-
[stackoverflow.com]: http://stackoverflow.com/users/1143732/richard-peck?tab=profile
|
431
|
-
[fork]: #fork-destination-box
|
432
|
-
[pull]: http://github.com/richpeck/exception_handler/pulls
|
433
|
-
[issues]: http://github.com/richpeck/exception_handler/issues
|
434
|
-
|
435
|
-
<!-- ################################### -->
|
436
|
-
<!-- ################################### -->
|
1
|
+
![Exception Handler](readme/title.jpg "Exception Handler Logo")
|
2
|
+
|
3
|
+
<p align="center">
|
4
|
+
<font size="4"><strong>Custom 404 & 500 production error pages for Rails 4 & 5.</font></strong>
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<p align="center">
|
8
|
+
<a href="http://badge.fury.io/rb/exception_handler"><img src="https://badge.fury.io/rb/exception_handler.svg" align="absmiddle"></a>
|
9
|
+
<a href="http://rubygems.org/gems/exception_handler"><img src="http://ruby-gem-downloads-badge.herokuapp.com/exception_handler/0.5.1?type=total&color=brightgreen" align="absmiddle" /></a>
|
10
|
+
<a href="https://codeclimate.com/github/richpeck/exception_handler"><img src="https://codeclimate.com/github/richpeck/exception_handler/badges/gpa.svg" align="absmiddle"/></a>
|
11
|
+
<a href="https://gemnasium.com/richpeck/exception_handler"><img src="https://gemnasium.com/richpeck/exception_handler.svg" align="absmiddle"></a>
|
12
|
+
<a href='https://coveralls.io/github/richpeck/exception_handler?branch=master'><img src='https://coveralls.io/repos/github/richpeck/exception_handler/badge.svg?branch=master' alt='Coverage Status' align="absmiddle" /></a>
|
13
|
+
<a href="https://travis-ci.org/richpeck/exception_handler"><img src="https://travis-ci.org/richpeck/exception_handler.svg?branch=master" align="absmiddle"></a>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p align="center">
|
17
|
+
<strong><a href="#install">Install</a></strong> → <strong><a href="#config">Setup</a></strong> → <strong><a href="#support">Support</a></strong>
|
18
|
+
</p>
|
19
|
+
|
20
|
+
---
|
21
|
+
|
22
|
+
<p align="center">
|
23
|
+
<img src="readme/version.jpg" /><br/>
|
24
|
+
</p>
|
25
|
+
|
26
|
+
<p align="center">
|
27
|
+
<img src="readme/check.png" height="22" title="Fully Responsive" align="absmiddle" /> <strong>Responsive</strong>
|
28
|
+
<img src="readme/check.png" height="22" title="Branded Error Pages" align="absmiddle" /> <strong>Branded Error Pages</strong>
|
29
|
+
<img src="readme/check.png" height="22" title="Middleware Exception Handling" align="absmiddle" /> <strong>Middleware Exception Handling</strong>
|
30
|
+
<img src="readme/check.png" height="22" title="Keep Users Informed" align="absmiddle" /> <strong>Fully Customizable</strong>
|
31
|
+
</p>
|
32
|
+
|
33
|
+
<p align="center">
|
34
|
+
<img src="readme/branded/1.jpg" width="425" title="Fully Branded Error Pages" /> <img src="readme/branded/2.jpg" width="425" title="Fully Branded Error Pages" />
|
35
|
+
<img src="readme/branded/3.jpg" width="425" title="Fully Branded Error Pages" /> <img src="readme/branded/4.jpg" width="425" title="Fully Branded Error Pages" />
|
36
|
+
</p>
|
37
|
+
|
38
|
+
---
|
39
|
+
|
40
|
+
<p align="center">
|
41
|
+
<img src="readme/rails.jpg" title="Version 0.7.5 Released Early 2017" />
|
42
|
+
</p>
|
43
|
+
|
44
|
+
---
|
45
|
+
|
46
|
+
<p align="center">
|
47
|
+
<img src="readme/titles/rails5.png" title="Fully Rails 5 Compatible" width="625" />
|
48
|
+
</p>
|
49
|
+
|
50
|
+
<p align="center">
|
51
|
+
<img src="readme/check_02.png" height="22" title="New Controller" align="absmiddle" /> <strong align="absmiddle">New Controller</strong>
|
52
|
+
<img src="readme/check_02.png" height="22" title="New Middleware" align="absmiddle" /> <strong align="absmiddle">New Middleware</strong>
|
53
|
+
<img src="readme/check_02.png" height="22" title="Full Test Suite" align="absmiddle" /> <strong align="absmiddle">Full Test Suite</strong>
|
54
|
+
<img src="readme/check_02.png" height="22" title="Rails 4 & 5 Compatible" align="absmiddle" /> <strong align="absmiddle">Fully Rails 4 & 5 Compatible</strong>
|
55
|
+
</p>
|
56
|
+
|
57
|
+
Brand new `controller` & `middleware` have made **`ExceptionHandler`** even more powerful & efficient. Now you can use `ExceptionHandler` with a [single click](#install) → **plug and play** custom exception pages:
|
58
|
+
|
59
|
+
<p align="center">
|
60
|
+
<br />
|
61
|
+
<img src="readme/400.png" title="400 Errors" width="430" />
|
62
|
+
<img src="readme/500.png" title="500 Errors" width="430" />
|
63
|
+
</p>
|
64
|
+
|
65
|
+
<p align="center">For over 3 years, <strong>ExceptionHandler</strong> has provided production-level <strong>Rails</strong> exception handling for <strong>4xx</strong> and <strong>5xx</strong> errors:</p>
|
66
|
+
|
67
|
+
![HTTP Error Codes][http_codes]
|
68
|
+
|
69
|
+
Since **browsers only read `4xx` & `5xx` error codes**, all Rails exceptions have to be inferred. Thus, `ExceptionHandler` simply has to manage how the `4xx` / `5xx` errors are passed to the browser.
|
70
|
+
|
71
|
+
Unlike other gems, **`ExceptionHandler` uses a custom [`controller`](app/controllers/exception_handler/exceptions_controller.rb) to build an [`@exception`](app/models/exception_handler/exception.rb) object**. This allows us to save the exception, email it or do anything else we may need. The gem has already been a massive success and we continue to actively maintain it.
|
72
|
+
|
73
|
+
Now you can try for yourself ...
|
74
|
+
|
75
|
+
|
76
|
+
----
|
77
|
+
|
78
|
+
<p align="center">
|
79
|
+
<br />
|
80
|
+
<img src="readme/titles/middleware.png" title="Middleware-Powered Exceptions" width="400" />
|
81
|
+
</p>
|
82
|
+
|
83
|
+
The secret lies in [**`config.exceptions_app`**][exception_app] ↴
|
84
|
+
|
85
|
+
> **`config.exceptions_app`** sets the exceptions application invoked by the **`ShowException`** middleware when an exception happens. Defaults to **`ActionDispatch::PublicExceptions.new(Rails.public_path)`**
|
86
|
+
|
87
|
+
![Exceptions handled by the ActiveDispatch::ShowExceptions Middleware][middleware]
|
88
|
+
|
89
|
+
Each time an exception is raised, [`ShowExceptions`][show_exception] takes the request and forwards it to `config.exceptions_app`. This is expected to return a response - allowing us to inject a [`controller`](app/controllers/exception_handler/exceptions_controller.rb):
|
90
|
+
|
91
|
+
![config.exceptions_app - The key to all Rails exceptions][exceptions_app]
|
92
|
+
|
93
|
+
Because our callback maintains the request, we are able to do whatever we need before serving a response. This is a **major** advantage over the "default" (routes). The routes invokes Rails twice and does not persist the request.
|
94
|
+
|
95
|
+
**`ExceptionHandler` is the only gem to provide middleware-powered exception handling.** It populates our custom `view` with details, giving us the ability to **maintain branding** when exceptions are raised:
|
96
|
+
|
97
|
+
![Exceptions handled by the ActiveDispatch::ShowExceptions Middleware][middleware]
|
98
|
+
|
99
|
+
**`ExceptionHandler` is the most EFFECTIVE and EFFICIENT gem to handle exceptions in Rails**.
|
100
|
+
|
101
|
+
Once invoked, its `model`, `controller` and `views` work together to serve the best responses to Rails errors ...
|
102
|
+
|
103
|
+
----------
|
104
|
+
|
105
|
+
<p align="center" id="install">
|
106
|
+
<br />
|
107
|
+
<img src="readme/titles/install.png" title="1 Click Install for ExceptionHandler 0.7.0 on Rails 5" width="400" />
|
108
|
+
<br />
|
109
|
+
<strong>Custom Rails Error Pages - ZERO configuration needed:</strong>
|
110
|
+
<br />
|
111
|
+
</p>
|
112
|
+
|
113
|
+
<p align="center">
|
114
|
+
<a href="http://rubygems.org/gems/exception_handler"><img src="readme/gem.jpg" /></a> <a href="http://rubygems.org/gems/exception_handler"><img src="readme/gemfile.jpg" /></a>
|
115
|
+
</p>
|
116
|
+
|
117
|
+
|
118
|
+
<p align="center">
|
119
|
+
You can install it from the <strong>CLI</strong> or <strong>Gemfile</strong> - it will AUTOMATICALLY run in <strong>production</strong>.
|
120
|
+
<br />
|
121
|
+
<strong>↓ To run in development, use <a href="#dev-mode">dev mode</a> ↓</strong>
|
122
|
+
</p>
|
123
|
+
|
124
|
+
---
|
125
|
+
|
126
|
+
<p align="center">
|
127
|
+
If you want to set it up your way, you can use these features...
|
128
|
+
</p>
|
129
|
+
|
130
|
+
<p align="center">
|
131
|
+
<a href="#config"><img src="readme/titles/icons/config.png" alt="Cinfiguration Options" align="absmiddle" height="24" /> Config</a> <a href="#dev-mode" title="Dev Mode"><img src="readme/titles/icons/dev.png" alt="Dev" align="absmiddle" height="24" /> Dev</a> <a href="#database"><img src="readme/titles/icons/database.png" alt="Database" align="absmiddle" height="24" /> Database</a> <a href="#email"><img src="readme/titles/icons/email.png" alt="Email" align="absmiddle" height="24" /> Email</a> <a href="#views"><img src="readme/titles/icons/views.png" alt="Views" align="absmiddle" height="24" /> Views</a> <a href="#locales"><img src="readme/titles/icons/locales.png" alt="Locales" align="absmiddle" height="20" /> Locales</a> <a href="#custom-exceptions"><img src="readme/titles/icons/custom.png" alt="Custom Exceptions" align="absmiddle" height="18" /> Custom Exceptions</a> <a href="#generators"><img src="readme/titles/icons/generators.png" alt="Generators" align="absmiddle" height="24" /> Generators</a>
|
132
|
+
</p>
|
133
|
+
|
134
|
+
----
|
135
|
+
|
136
|
+
## Config
|
137
|
+
|
138
|
+
**From [`0.4.7`](https://github.com/richpeck/exception_handler/releases/tag/0.4.6), `ExceptionHandler` manages its [config](lib/exception_handler/config.rb#L45) from the central Rails `config` hash:**
|
139
|
+
|
140
|
+
[![config][config]](lib/exception_handler/config.rb#L45)
|
141
|
+
|
142
|
+
If you're using an [`engine`](http://guides.rubyonrails.org/engines.html), you don't need to use an `initializer`:
|
143
|
+
|
144
|
+
# lib/engine.rb
|
145
|
+
module YourModule
|
146
|
+
class Engine < Rails::Engine
|
147
|
+
|
148
|
+
# => ExceptionHandler
|
149
|
+
# => Works in and out of an initializer
|
150
|
+
config.exception_handler = {
|
151
|
+
dev: false,
|
152
|
+
db: true
|
153
|
+
}
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
You only need to provide the inputs you want, for example:
|
159
|
+
|
160
|
+
# config/application.rb
|
161
|
+
config.exception_handler = { dev: true }
|
162
|
+
|
163
|
+
# config/environments/production.rb
|
164
|
+
config.exception_handler = { social: { fusion: "flutils" }}
|
165
|
+
|
166
|
+
----
|
167
|
+
|
168
|
+
## Dev Mode
|
169
|
+
|
170
|
+
**To enable `ExceptionHandler` in dev, enable the [`dev`](lib/exception_handler/config.rb#L38) option:**
|
171
|
+
|
172
|
+
![Dev][dev_mode]
|
173
|
+
|
174
|
+
This disables [`config.consider_all_requests_local`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration), making Rails behave as it would in production:
|
175
|
+
|
176
|
+
![Dev][dev_img]
|
177
|
+
|
178
|
+
----
|
179
|
+
|
180
|
+
## Database
|
181
|
+
|
182
|
+
**We also have `ActiveRecord` integration.**
|
183
|
+
|
184
|
+
If you want to save your exceptions to `db`, you need to enable the `db` config option:
|
185
|
+
|
186
|
+
# config/application.rb
|
187
|
+
config.exception_handler = {
|
188
|
+
db: true
|
189
|
+
}
|
190
|
+
|
191
|
+
This enables `ActiveRecord::Base` on the [`Exception`](app/models/exception_handler/exception.rb) class, allowing us to save to the database.
|
192
|
+
|
193
|
+
In order for this to work, your db needs the correct table.
|
194
|
+
|
195
|
+
To do this, once you've enabled the option, run `rails db:migrate` from your console. Our new [`migration system`](https://github.com/richpeck/exception_handler/tree/readme#migrations) will automatically run the migration.
|
196
|
+
|
197
|
+
---
|
198
|
+
|
199
|
+
## Email
|
200
|
+
|
201
|
+
**`ExceptionHandler` also now sends email notifications.**
|
202
|
+
|
203
|
+
If you want to receive emails whenever your application raises an error, you can do so by adding your email to the config:
|
204
|
+
|
205
|
+
# config/application.rb
|
206
|
+
config.exception_handler = {
|
207
|
+
email: "your@email.com"
|
208
|
+
}
|
209
|
+
|
210
|
+
> **Please Note** this requires [`ActionMailer`](http://guides.rubyonrails.org/action_mailer_basics.html). If you don't have any outbound SMTP server, [`SendGrid`](http://sendgrid.com) is free.
|
211
|
+
|
212
|
+
[Full tutorial here](https://github.com/richpeck/exception_handler/wiki/2-Email)
|
213
|
+
|
214
|
+
---
|
215
|
+
|
216
|
+
## Views
|
217
|
+
|
218
|
+
**From [`0.7.0`](#070), we overhauled the view system:**
|
219
|
+
|
220
|
+
![View][view_img]
|
221
|
+
|
222
|
+
[Wiew](app/views/exception_handler/exceptions/show.html.erb) is modular - `@exception` populated with [`locales`](#locales).
|
223
|
+
|
224
|
+
---
|
225
|
+
|
226
|
+
## Locales
|
227
|
+
|
228
|
+
**[`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5) introduced [locales](config/locales/exception_handler.yml) ...**
|
229
|
+
|
230
|
+
[[ locales ]]
|
231
|
+
|
232
|
+
The `ExceptionHandler` view is populated by [`@exception.description`](app/models/exception_handler/exception.rb#L121), which pulls from the `locales`.
|
233
|
+
|
234
|
+
If you want custom messages, you need the following. The key is defined by the HTTP [`status_code`](https://github.com/rack/rack/blob/1.5.2/lib/rack/utils.rb#L544)
|
235
|
+
|
236
|
+
# config/locales/en.yml
|
237
|
+
en:
|
238
|
+
exception_handler:
|
239
|
+
not_found: "Your message here"
|
240
|
+
unauthorized: "You need to login to continue"
|
241
|
+
internal_server_error: "This is a test to show the %{status} of the error"
|
242
|
+
|
243
|
+
You get access to `%{message}` and `%{status}`, both inferring from `@exception`.
|
244
|
+
|
245
|
+
---
|
246
|
+
|
247
|
+
## Layout
|
248
|
+
|
249
|
+
**The `layout` has also been improved ↴**
|
250
|
+
|
251
|
+
![Layout][layout_img]
|
252
|
+
|
253
|
+
We now assign layouts to the **status code** of the response:
|
254
|
+
|
255
|
+
![Layout][layouts_img]
|
256
|
+
|
257
|
+
By default, `5xx` errors are shown with our [`exception` layout][layout] - this can be overridden by changing the `config` to use a layout of your choice. If you want to inherit the `ApplicationController` layout, assign the codes to `nil`.
|
258
|
+
|
259
|
+
---
|
260
|
+
|
261
|
+
|
262
|
+
## Custom Exceptions
|
263
|
+
|
264
|
+
**Custom Exceptions also supported in [`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)**
|
265
|
+
|
266
|
+
Rails handles this for us - [**`config.action_dispatch.rescue_responses`**][rescue_responses] ↴
|
267
|
+
|
268
|
+
![ActionDispatch][config.action_dispatch.rescue_responses]
|
269
|
+
|
270
|
+
You need to add to the `rescue_responses` hash in your app's config (mapped to [`status codes`](https://github.com/rack/rack/blob/1.5.2/lib/rack/utils.rb#L544)):
|
271
|
+
|
272
|
+
# config/application.rb
|
273
|
+
config.action_dispatch.rescue_responses["ActionController::YourError"] = :bad_request
|
274
|
+
|
275
|
+
Because `HTTP` can only process `4xx` / `5xx` errors, if `Rails` raises an exception, it needs to assign one of the error status codes. **Default** is [`internal_server_error`](https://github.com/rack/rack/blob/1.5.2/lib/rack/utils.rb#L595) - if you'd prefer your app to just return `500` errors for your custom exception, you don't need to explicitly declare them.
|
276
|
+
|
277
|
+
---
|
278
|
+
|
279
|
+
## Generators
|
280
|
+
|
281
|
+
**You can generate `ExceptionHandler` into your own application.**
|
282
|
+
|
283
|
+
[[ Generator ]]
|
284
|
+
|
285
|
+
The following commands will copy the directories...
|
286
|
+
|
287
|
+
rails g exception_handler:views
|
288
|
+
rails g exception_handler:views -v views
|
289
|
+
rails g exception_handler:views -v controllers
|
290
|
+
rails g exception_handler:views -v models
|
291
|
+
rails g exception_handler:views -v assets
|
292
|
+
rails g exception_handler:views -v views controllers models assets
|
293
|
+
|
294
|
+
If you don't include any switches, this will copy **all** the folders put into your app.
|
295
|
+
|
296
|
+
Each switch defines which folders you want (EG `-v views` will only copy `views` dir).
|
297
|
+
|
298
|
+
---
|
299
|
+
|
300
|
+
### Migrations (deprecated)
|
301
|
+
|
302
|
+
**From [`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5), the `migration` generator has been removed in favour of our own [migration system](lib/exception_handler/engine.rb#L58)**
|
303
|
+
|
304
|
+
You don't need to generate a migration any more.
|
305
|
+
|
306
|
+
If you set the `db` option in config, run `rails db:migrate` and the migration will be run.
|
307
|
+
|
308
|
+
To rollback, use the following:
|
309
|
+
|
310
|
+
rails db:migrate:down VERSION=000000
|
311
|
+
|
312
|
+
> The drawback to this is that if you remove `ExceptionHandler` before you rollback the migration, it won't exist anymore. You can **only** fire the `rollback` when you have `ExceptionHandler` installed.
|
313
|
+
|
314
|
+
---
|
315
|
+
|
316
|
+
## Support
|
317
|
+
|
318
|
+
[Issues](https://github.com/richpeck/exception_handler/issues)
|
319
|
+
|
320
|
+
---
|
321
|
+
|
322
|
+
## Changelog
|
323
|
+
|
324
|
+
### [0.7.5](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)
|
325
|
+
- [x] [HTTP status layouts](#layouts)
|
326
|
+
|
327
|
+
### [0.7.0](https://github.com/richpeck/exception_handler/releases/tag/0.7.0)
|
328
|
+
- [x] Wildcard mime types
|
329
|
+
- [x] [Custom exceptions](#custom_exceptions)
|
330
|
+
- [x] Test suite integration
|
331
|
+
- [x] [Email](#email)
|
332
|
+
- [x] [Model backend](#database)
|
333
|
+
- [x] Sprockets 4+
|
334
|
+
- [x] New layout
|
335
|
+
- [x] Readme / wiki overhaul
|
336
|
+
|
337
|
+
### [0.6.5](https://github.com/richpeck/exception_handler/releases/tag/0.6.5)
|
338
|
+
- [x] Streamlined interface
|
339
|
+
- [x] ActiveRecord / Middleware overhaul
|
340
|
+
- [x] Supports Sprockets 4+ ([`manifest.js`](http://eileencodes.com/posts/the-sprockets-4-manifest/))
|
341
|
+
- [x] Email integration
|
342
|
+
- [x] Asset overhaul & improvement
|
343
|
+
- [x] Removed dependencies
|
344
|
+
|
345
|
+
### [0.5.0](https://github.com/richpeck/exception_handler/releases/tag/0.5.0)
|
346
|
+
- [x] Locales
|
347
|
+
- [x] Email notifications
|
348
|
+
- [x] Full test suite
|
349
|
+
- [x] Rails 4.2 & Rails 5.0 native ([`request.env`](https://github.com/rails/rails/commit/05934d24aff62d66fc62621aa38dae6456e276be) fix)
|
350
|
+
- [x] Controller fixed
|
351
|
+
- [x] `DB` fixed
|
352
|
+
- [x] Legacy initializer support ([more](https://github.com/richpeck/exception_handler/wiki/1-Setup))
|
353
|
+
- [x] Rails asset management improvement
|
354
|
+
- [x] Reduced gem file size
|
355
|
+
|
356
|
+
### [0.4.7](https://github.com/richpeck/exception_handler/releases/tag/0.4.6)
|
357
|
+
- [x] New config system
|
358
|
+
- [x] Fixed controller layout issues
|
359
|
+
- [x] Streamlined middleware
|
360
|
+
- [x] New layout & interface
|
361
|
+
|
362
|
+
----
|
363
|
+
|
364
|
+
[![404 + 500 Errors][banner]][rubygems]
|
365
|
+
|
366
|
+
<p align="center">
|
367
|
+
<strong><a href="#">ExceptionHandler</a> is now the leading custom error pages gem for Rails.</strong>
|
368
|
+
<br />
|
369
|
+
No other gem is as simple or effective at providing beautiful exception pages in production.
|
370
|
+
</p>
|
371
|
+
|
372
|
+
<p align="center">
|
373
|
+
<a href="http://badge.fury.io/rb/exception_handler"><img src="https://badge.fury.io/rb/exception_handler.svg" align="absmiddle"></a>
|
374
|
+
<a href="http://rubygems.org/gems/exception_handler"><img src="http://ruby-gem-downloads-badge.herokuapp.com/exception_handler/0.5.1?type=total&color=brightgreen" align="absmiddle" /></a>
|
375
|
+
<a href="https://codeclimate.com/github/richpeck/exception_handler"><img src="https://codeclimate.com/github/richpeck/exception_handler/badges/gpa.svg" align="absmiddle"/></a>
|
376
|
+
<a href="https://gemnasium.com/richpeck/exception_handler"><img src="https://gemnasium.com/richpeck/exception_handler.svg" align="absmiddle"></a>
|
377
|
+
<a href='https://coveralls.io/github/richpeck/exception_handler?branch=master'><img src='https://coveralls.io/repos/github/richpeck/exception_handler/badge.svg?branch=master' alt='Coverage Status' align="absmiddle" /></a>
|
378
|
+
<a href="https://travis-ci.org/richpeck/exception_handler"><img src="https://travis-ci.org/richpeck/exception_handler.svg?branch=master" align="absmiddle"></a>
|
379
|
+
</p>
|
380
|
+
|
381
|
+
<p align="center">
|
382
|
+
<strong><a href="https://rubygems.org/gems/exception_handler">Download Here</a></strong>
|
383
|
+
</p>
|
384
|
+
|
385
|
+
----------
|
386
|
+
|
387
|
+
:copyright: <a href="http://www.frontlineutilities.co.uk" align="absmiddle" ><img src="readme/fl.jpg" height="22" align="absmiddle" /></a> <a href="http://stackoverflow.com/users/1143732/richard-peck?tab=profile" align="absmiddle" ><img src="https://avatars0.githubusercontent.com/u/1104431" height="22" align="absmiddle" /></a>
|
388
|
+
|
389
|
+
<!-- ################################### -->
|
390
|
+
<!-- ################################### -->
|
391
|
+
|
392
|
+
<!-- Refs -->
|
393
|
+
<!-- Comments http://stackoverflow.com/a/20885980/1143732 -->
|
394
|
+
<!-- Images https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#images -->
|
395
|
+
|
396
|
+
<!-- Images -->
|
397
|
+
[dev_mode]: readme/dev_mode.jpg
|
398
|
+
[dev_img]: readme/dev.png
|
399
|
+
[layouts_img]: readme/layouts.jpg
|
400
|
+
[layout_img]: readme/layout.png
|
401
|
+
[view_img]: readme/view.jpg
|
402
|
+
[http_codes]: readme/http_codes.png
|
403
|
+
[config]: readme/config.jpg
|
404
|
+
[config.action_dispatch.rescue_responses]: readme/config.action_dispatch.rescue_responses.jpg
|
405
|
+
[banner]: readme/banner.jpg
|
406
|
+
[gem]: readme/gem.jpg
|
407
|
+
[gemfile]: readme/gemfile.jpg
|
408
|
+
[middleware]: readme/middleware.jpg
|
409
|
+
[exceptions_app]: readme/exceptions_app.jpg
|
410
|
+
[view]: readme/titles/view.jpg
|
411
|
+
[dev]: readme/titles/dev.jpg
|
412
|
+
[db]: readme/titles/db.png
|
413
|
+
[support]: readme/titles/support.png "Support"
|
414
|
+
[changelog]: readme/titles/changelog.png "Changelog"
|
415
|
+
[contribution]: readme/titles/contributions.png "Contributions"
|
416
|
+
[fl]: readme/fl.jpg "Frontline Utilities LTD"
|
417
|
+
[profile]: https://avatars0.githubusercontent.com/u/1104431 "R Peck"
|
418
|
+
|
419
|
+
<!-- Links -->
|
420
|
+
[better_errors]: https://github.com/charliesome/better_errors
|
421
|
+
[layout]: app/views/layouts/exception.html.erb
|
422
|
+
[status_codes]: http://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option
|
423
|
+
[stackoverflow]: http://stackoverflow.com/questions/ask?tags=ruby-on-rails+exception-handler
|
424
|
+
[rescue_responses]: http://guides.rubyonrails.org/configuring.html#configuring-action-dispatch
|
425
|
+
[latest]: https://github.com/richpeck/exception_handler/releases/latest
|
426
|
+
[show_exception]: https://github.com/rails/rails/blob/4-0-stable/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
|
427
|
+
[exception_app]: http://guides.rubyonrails.org/configuring.html#rails-general-configuration
|
428
|
+
[rubygems]: http://rubygems.org/gems/exception_handler
|
429
|
+
[frontlineutilities.co.uk]: http://www.frontlineutilities.co.uk
|
430
|
+
[stackoverflow.com]: http://stackoverflow.com/users/1143732/richard-peck?tab=profile
|
431
|
+
[fork]: #fork-destination-box
|
432
|
+
[pull]: http://github.com/richpeck/exception_handler/pulls
|
433
|
+
[issues]: http://github.com/richpeck/exception_handler/issues
|
434
|
+
|
435
|
+
<!-- ################################### -->
|
436
|
+
<!-- ################################### -->
|