exception_handler 0.7.5 → 0.8.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +5 -5
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +51 -33
  4. data/.rspec +3 -4
  5. data/.slugignore +7 -0
  6. data/.travis.yml +13 -5
  7. data/Gemfile +16 -13
  8. data/README.md +643 -443
  9. data/Rakefile +7 -7
  10. data/app/assets/stylesheets/exception_handler.css.erb +23 -18
  11. data/app/assets/stylesheets/styles/_base.css.erb +28 -35
  12. data/app/assets/stylesheets/styles/_exception.css.erb +106 -105
  13. data/app/assets/stylesheets/styles/_footer.css.erb +24 -24
  14. data/app/assets/stylesheets/styles/_responsive.css +5 -5
  15. data/app/controllers/exception_handler/exceptions_controller.rb +66 -55
  16. data/app/mailers/exception_handler/exception_mailer.rb +17 -17
  17. data/app/models/exception_handler/exception.rb +200 -191
  18. data/app/views/exception_handler/exceptions/show.html.erb +3 -3
  19. data/app/views/exception_handler/mailers/layout.haml +8 -8
  20. data/app/views/exception_handler/mailers/layout.text.erb +1 -1
  21. data/app/views/exception_handler/mailers/new_exception.erb +4 -4
  22. data/app/views/layouts/exception.html.erb +32 -27
  23. data/app/views/layouts/mailer.html.erb +5 -0
  24. data/app/views/layouts/mailer.text.erb +1 -0
  25. data/config/locales/exception_handler.en.yml +28 -29
  26. data/config/routes.rb +42 -0
  27. data/db/migrate/000000_create_errors.rb +34 -34
  28. data/exception_handler.gemspec +64 -80
  29. data/lib/exception_handler.rb +56 -45
  30. data/lib/exception_handler/config.rb +185 -103
  31. data/lib/exception_handler/engine.rb +78 -60
  32. data/lib/exception_handler/version.rb +25 -0
  33. data/lib/generators/exception_handler/views_generator.rb +33 -33
  34. data/spec/controllers/controller_spec.rb +107 -0
  35. data/spec/dummy/.rspec +1 -0
  36. data/spec/dummy/.ruby-version +1 -0
  37. data/spec/dummy/Rakefile +6 -6
  38. data/spec/dummy/app/assets/config/manifest.js +3 -4
  39. data/spec/dummy/app/assets/javascripts/application.js +15 -13
  40. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  41. data/spec/dummy/app/assets/stylesheets/application.css +15 -15
  42. data/spec/dummy/app/channels/application_cable/channel.rb +4 -5
  43. data/spec/dummy/app/channels/application_cable/connection.rb +4 -5
  44. data/spec/dummy/app/controllers/application_controller.rb +2 -5
  45. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  46. data/spec/dummy/app/jobs/application_job.rb +2 -2
  47. data/spec/dummy/app/mailers/application_mailer.rb +4 -4
  48. data/spec/dummy/app/models/application_record.rb +3 -3
  49. data/spec/dummy/app/views/layouts/application.html.erb +15 -15
  50. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -13
  51. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -1
  52. data/spec/dummy/bin/bundle +3 -3
  53. data/spec/dummy/bin/rails +4 -4
  54. data/spec/dummy/bin/rake +4 -4
  55. data/spec/dummy/bin/setup +36 -34
  56. data/spec/dummy/bin/update +31 -29
  57. data/spec/dummy/bin/yarn +11 -0
  58. data/spec/dummy/config.ru +5 -8
  59. data/spec/dummy/config/application.rb +18 -21
  60. data/spec/dummy/config/boot.rb +5 -5
  61. data/spec/dummy/config/cable.yml +10 -10
  62. data/spec/dummy/config/database.yml +25 -25
  63. data/spec/dummy/config/environment.rb +5 -5
  64. data/spec/dummy/config/environments/development.rb +61 -62
  65. data/spec/dummy/config/environments/production.rb +94 -87
  66. data/spec/dummy/config/environments/test.rb +46 -42
  67. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -6
  68. data/spec/dummy/config/initializers/assets.rb +14 -11
  69. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  70. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  71. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -5
  72. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
  73. data/spec/dummy/config/initializers/inflections.rb +16 -16
  74. data/spec/dummy/config/initializers/mime_types.rb +4 -4
  75. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  76. data/spec/dummy/config/locales/en.yml +33 -23
  77. data/spec/dummy/config/puma.rb +34 -47
  78. data/spec/dummy/config/routes.rb +3 -6
  79. data/spec/dummy/config/storage.yml +34 -0
  80. data/spec/dummy/package.json +5 -0
  81. data/spec/dummy/public/404.html +67 -67
  82. data/spec/dummy/public/422.html +67 -67
  83. data/spec/dummy/public/500.html +66 -66
  84. data/spec/dummy/spec/rails_helper.rb +57 -0
  85. data/spec/dummy/spec/spec_helper.rb +100 -0
  86. data/spec/dummy/storage/.keep +0 -0
  87. data/spec/features/asset_spec.rb +61 -0
  88. data/spec/features/config_spec.rb +51 -0
  89. data/spec/features/engine_spec.rb +180 -0
  90. data/spec/mailers/mailer_spec.rb +26 -0
  91. data/spec/models/model_spec.rb +26 -0
  92. data/spec/routing/routing_spec.rb +85 -0
  93. data/spec/spec_helper.rb +101 -55
  94. data/spec/views/views_spec.rb +29 -0
  95. metadata +54 -28
  96. data/.gitattributes +0 -1
  97. data/LICENSE.txt +0 -22
  98. data/app/assets/images/exception_handler/bg.jpg +0 -0
  99. data/app/assets/images/exception_handler/bg_overlay.png +0 -0
  100. data/spec/database.yml +0 -3
  101. data/spec/dummy/app/assets/javascripts/cable.coffee +0 -11
  102. data/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +0 -6
  103. data/spec/dummy/config/initializers/callback_terminator.rb +0 -6
  104. data/spec/dummy/config/initializers/per_form_csrf_tokens.rb +0 -4
  105. data/spec/dummy/config/initializers/request_forgery_protection.rb +0 -4
  106. data/spec/dummy/config/initializers/session_store.rb +0 -3
  107. data/spec/dummy/config/secrets.yml +0 -22
  108. data/spec/exception_handler.rb +0 -22
  109. data/spec/exception_handler/exception_controller_spec.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ccc92609ab7af5a0f65736e1578aaef57b51a2d7
4
- data.tar.gz: 1843d7a57a2551baa486a8579e60594eca2e2d5f
2
+ SHA256:
3
+ metadata.gz: ba54148f25815a5f2df409c4261ade99ffa4f2f96c4a0ae354149ba539bffac3
4
+ data.tar.gz: ee20ae2ed6c8be539b8ffb0388da0b2680aaaaf5aa793a0df49fe38e5230ea2e
5
5
  SHA512:
6
- metadata.gz: 0af19ea19133e86ad15a43f9324ee923ebdce75a7747543bd57f799ca16c8b14f0f24b81ce6ed144c8a6cd78169c2aa5e0b6c8bc5780af801bf1d169acc57fb9
7
- data.tar.gz: 0740300edaa518daf6db9e133b75650684bdcaf3b276b84c7e4568b9fd61d5032d8d0c14c5037ceaa72998c58076d059a7970b2a2d8321dbd95c526cb8e4fddd
6
+ metadata.gz: e5a14eeb3beb2ffab2fe1289acd377423242d980294cf0872e85ba86aeb7165027de92b2057d034a1730ff4e38fb716b38052c81d1502143a658367e1a1ae23c
7
+ data.tar.gz: '0890e4e17d5bb8c94cefb0dc24adb8d40f7fc49c8c9cb7f4e6904221e61750dd23f886ce1af3141316f5dc14152e8ae6cabc1bd3285a90a6e5c3646d8fa7783d'
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -1,33 +1,51 @@
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
- # http://stackoverflow.com/questions/8865848/comments-in-gitignore
26
- # https://gist.github.com/danielpcox/4636520
27
-
28
- log/*.log
29
- pkg/
30
- spec/dummy/db/*.sqlite3
31
- spec/dummy/log/*.log
32
- spec/dummy/tmp/
33
- spec/dummy/.sass-cache
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
+ .rspec_status
25
+ /coverage/
26
+
27
+ ##########################################################
28
+ ##########################################################
29
+
30
+ # http://stackoverflow.com/questions/8865848/comments-in-gitignore
31
+
32
+ ##########################################################
33
+ ##########################################################
34
+
35
+ # Desktop INI (Windows)
36
+ desktop.ini
37
+
38
+ # Readme Source (PSD's)
39
+ readme/source
40
+
41
+ # Git BFG
42
+ .git.bfg-report
43
+ .git.bfg-report/2017-06-29/07-53-00
44
+
45
+ # Specs
46
+ log/*.log
47
+ pkg/
48
+ spec/dummy/db/*.sqlite3
49
+ spec/dummy/log/*.log
50
+ spec/dummy/tmp/
51
+ spec/dummy/.sass-cache
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
- --color
2
- --format progress
3
- --require spec_helper
4
- --format documentation
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.slugignore ADDED
@@ -0,0 +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
data/.travis.yml CHANGED
@@ -1,5 +1,13 @@
1
- rvm:
2
- - 2.2.4
3
- - 2.3.2
4
- - 2.4.0
5
- - ruby-head
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ - 2.3.7
5
+ - 2.4.4
6
+ - 2.5.1
7
+ - ruby-head
8
+ notifications:
9
+ - false
10
+ scripts:
11
+ - bundle exec rspec
12
+ after_script:
13
+ - bundle exec rake coveralls:push
data/Gemfile CHANGED
@@ -1,13 +1,16 @@
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
+ # => Required for Windows
14
+ gem 'tzinfo-data' if Gem.win_platform? # => TZInfo For Windows
15
+
16
+ ###########################################
data/README.md CHANGED
@@ -1,443 +1,643 @@
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" />&nbsp; <strong>Responsive</strong> &nbsp;
28
- <img src="readme/check.png" height="22" title="Branded Error Pages" align="absmiddle" />&nbsp; <strong>Branded Error Pages</strong> &nbsp;
29
- <img src="readme/check.png" height="22" title="Middleware Exception Handling" align="absmiddle" />&nbsp; <strong>Middleware Exception Handling</strong> &nbsp;
30
- <img src="readme/check.png" height="22" title="Keep Users Informed" align="absmiddle" />&nbsp; <strong>Fully Customizable</strong> &nbsp;
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" />&nbsp; <strong align="absmiddle">New Controller</strong> &nbsp;
52
- <img src="readme/check_02.png" height="22" title="New Middleware" align="absmiddle" />&nbsp; <strong align="absmiddle">New Middleware</strong> &nbsp;
53
- <img src="readme/check_02.png" height="22" title="Full Test Suite" align="absmiddle" />&nbsp; <strong align="absmiddle">Full Test Suite</strong> &nbsp;
54
- <img src="readme/check_02.png" height="22" title="Rails 4 & 5 Compatible" align="absmiddle" />&nbsp; <strong align="absmiddle">Fully Rails 4 & 5 Compatible</strong> &nbsp;
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
- > ```app.config.exceptions_app = ->(env) { ExceptionHandler::ExceptionsController.action(:show).call(env) }```
92
-
93
- ![config.exceptions_app - The key to all Rails exceptions][exceptions_app]
94
-
95
- 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.
96
-
97
- **`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:
98
-
99
- ![Exceptions handled by the ActiveDispatch::ShowExceptions Middleware][middleware]
100
-
101
- **`ExceptionHandler` is the most EFFECTIVE and EFFICIENT gem to handle exceptions in Rails**.
102
-
103
- Once invoked, its `model`, `controller` and `views` work together to serve the best responses to Rails errors ...
104
-
105
- ----------
106
-
107
- <p align="center" id="install">
108
- <br />
109
- <img src="readme/titles/install.png" title="1 Click Install for ExceptionHandler 0.7.0 on Rails 5" width="400" />
110
- <br />
111
- <strong>Custom Rails Error Pages - ZERO configuration needed:</strong>
112
- <br />
113
- </p>
114
-
115
- <p align="center">
116
- <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>
117
- </p>
118
-
119
-
120
- <p align="center">
121
- You can install it from the <strong>CLI</strong> or <strong>Gemfile</strong> - it will AUTOMATICALLY run in <strong>production</strong>.
122
- <br />
123
- <strong>↓ To run in development, use <a href="#dev-mode">dev mode</a> ↓</strong>
124
- </p>
125
-
126
- ---
127
-
128
- <p align="center">
129
- If you want to set it up your way, you can use these features...
130
- </p>
131
-
132
- <p align="center">
133
- <a href="#config"><img src="readme/titles/icons/config.png" alt="Cinfiguration Options" align="absmiddle" height="24" /> Config</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#dev-mode" title="Dev Mode"><img src="readme/titles/icons/dev.png" alt="Dev" align="absmiddle" height="24" /> Dev</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#database"><img src="readme/titles/icons/database.png" alt="Database" align="absmiddle" height="24" /> Database</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#email"><img src="readme/titles/icons/email.png" alt="Email" align="absmiddle" height="24" /> Email</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#views"><img src="readme/titles/icons/views.png" alt="Views" align="absmiddle" height="24" /> Views</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#locales"><img src="readme/titles/icons/locales.png" alt="Locales" align="absmiddle" height="24" /> Locales</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#custom-exceptions"><img src="readme/titles/icons/custom.png" alt="Custom Exceptions" align="absmiddle" height="24" /> Custom Exceptions</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#generators"><img src="readme/titles/icons/generators.png" alt="Generators" align="absmiddle" height="24" /> Generators</a>
134
- </p>
135
-
136
- ----
137
-
138
- ## Config
139
-
140
- **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:**
141
-
142
- [![config][config]](lib/exception_handler/config.rb#L45)
143
-
144
- If you're using an [`engine`](http://guides.rubyonrails.org/engines.html), you don't need to use an `initializer`:
145
-
146
- # lib/engine.rb
147
- module YourModule
148
- class Engine < Rails::Engine
149
-
150
- # => ExceptionHandler
151
- # => Works in and out of an initializer
152
- config.exception_handler = {
153
- dev: false,
154
- db: true
155
- }
156
- end
157
-
158
- end
159
-
160
- You only need to provide the inputs you want, for example:
161
-
162
- # config/application.rb
163
- config.exception_handler = { dev: true }
164
-
165
- # config/environments/production.rb
166
- config.exception_handler = { social: { fusion: "flutils" }}
167
-
168
- ----
169
-
170
- ## Dev Mode
171
-
172
- **To enable `ExceptionHandler` in dev, enable the [`dev`](lib/exception_handler/config.rb#L38) option:**
173
-
174
- # config/application.rb
175
- config.exception_handler = { dev: true }
176
-
177
- ![Dev][dev_mode]
178
-
179
- This disables [`config.consider_all_requests_local`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration), making Rails behave as it would in production:
180
-
181
- ![Dev][dev_img]
182
-
183
- This should be used temporarily.
184
-
185
- ----
186
-
187
- ## Database
188
-
189
- **We also have `ActiveRecord` integration.**
190
-
191
- If you want to save your exceptions to `db`, you need to enable the `db` config option:
192
-
193
- # config/application.rb
194
- config.exception_handler = {
195
- db: true
196
- }
197
-
198
- This enables `ActiveRecord::Base` on the [`Exception`](app/models/exception_handler/exception.rb) class, allowing us to save to the database.
199
-
200
- In order for this to work, your db needs the correct table.
201
-
202
- 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.
203
-
204
- ---
205
-
206
- ## Email
207
-
208
- **`ExceptionHandler` also now sends email notifications.**
209
-
210
- If you want to receive emails whenever your application raises an error, you can do so by adding your email to the config:
211
-
212
- # config/application.rb
213
- config.exception_handler = {
214
- email: "your@email.com"
215
- }
216
-
217
- > **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.
218
-
219
- [Full tutorial here](https://github.com/richpeck/exception_handler/wiki/2-Email)
220
-
221
- ---
222
-
223
- ## Views
224
-
225
- **From [`0.7.0`](#070), we overhauled the view system:**
226
-
227
- ![View][view_img]
228
-
229
- [Wiew](app/views/exception_handler/exceptions/show.html.erb) is modular - `@exception` populated with [`locales`](#locales).
230
-
231
- ---
232
-
233
- ## Locales
234
-
235
- **[`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5) introduced [locales](config/locales/exception_handler.yml) ...**
236
-
237
- [[ locales ]]
238
-
239
- The `ExceptionHandler` view is populated by [`@exception.description`](app/models/exception_handler/exception.rb#L121), which pulls from the `locales`.
240
-
241
- 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)
242
-
243
- # config/locales/en.yml
244
- en:
245
- exception_handler:
246
- not_found: "Your message here"
247
- unauthorized: "You need to login to continue"
248
- internal_server_error: "This is a test to show the %{status} of the error"
249
-
250
- You get access to `%{message}` and `%{status}`, both inferring from `@exception`.
251
-
252
- ---
253
-
254
- ## Layout
255
-
256
- **The `layout` has also been improved ↴**
257
-
258
- ![Layout][layout_img]
259
-
260
- We now assign layouts to the **status code** of the response:
261
-
262
- ![Layout][layouts_img]
263
-
264
- 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`.
265
-
266
- ---
267
-
268
-
269
- ## Custom Exceptions
270
-
271
- **Custom Exceptions also supported in [`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)**
272
-
273
- Rails handles this for us - [**`config.action_dispatch.rescue_responses`**][rescue_responses] ↴
274
-
275
- ![ActionDispatch][config.action_dispatch.rescue_responses]
276
-
277
- 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)):
278
-
279
- # config/application.rb
280
- config.action_dispatch.rescue_responses["ActionController::YourError"] = :bad_request
281
-
282
- 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.
283
-
284
- ---
285
-
286
- ## Generators
287
-
288
- **You can generate `ExceptionHandler` into your own application.**
289
-
290
- [[ Generator ]]
291
-
292
- The following commands will copy the directories...
293
-
294
- rails g exception_handler:views
295
- rails g exception_handler:views -v views
296
- rails g exception_handler:views -v controllers
297
- rails g exception_handler:views -v models
298
- rails g exception_handler:views -v assets
299
- rails g exception_handler:views -v views controllers models assets
300
-
301
- If you don't include any switches, this will copy **all** the folders put into your app.
302
-
303
- Each switch defines which folders you want (EG `-v views` will only copy `views` dir).
304
-
305
- ---
306
-
307
- ### Migrations (deprecated)
308
-
309
- **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)**
310
-
311
- You don't need to generate a migration any more.
312
-
313
- If you set the `db` option in config, run `rails db:migrate` and the migration will be run.
314
-
315
- To rollback, use the following:
316
-
317
- rails db:migrate:down VERSION=000000
318
-
319
- > 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.
320
-
321
- ---
322
-
323
- ## Support
324
-
325
- [Issues](https://github.com/richpeck/exception_handler/issues)
326
-
327
- ---
328
-
329
- ## Changelog
330
-
331
- ### [0.7.5](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)
332
- - [x] [HTTP status layouts](#layouts)
333
-
334
- ### [0.7.0](https://github.com/richpeck/exception_handler/releases/tag/0.7.0)
335
- - [x] Wildcard mime types
336
- - [x] [Custom exceptions](#custom_exceptions)
337
- - [x] Test suite integration
338
- - [x] [Email](#email)
339
- - [x] [Model backend](#database)
340
- - [x] Sprockets 4+
341
- - [x] New layout
342
- - [x] Readme / wiki overhaul
343
-
344
- ### [0.6.5](https://github.com/richpeck/exception_handler/releases/tag/0.6.5)
345
- - [x] Streamlined interface
346
- - [x] ActiveRecord / Middleware overhaul
347
- - [x] Supports Sprockets 4+ ([`manifest.js`](http://eileencodes.com/posts/the-sprockets-4-manifest/))
348
- - [x] Email integration
349
- - [x] Asset overhaul & improvement
350
- - [x] Removed dependencies
351
-
352
- ### [0.5.0](https://github.com/richpeck/exception_handler/releases/tag/0.5.0)
353
- - [x] Locales
354
- - [x] Email notifications
355
- - [x] Full test suite
356
- - [x] Rails 4.2 & Rails 5.0 native ([`request.env`](https://github.com/rails/rails/commit/05934d24aff62d66fc62621aa38dae6456e276be) fix)
357
- - [x] Controller fixed
358
- - [x] `DB` fixed
359
- - [x] Legacy initializer support ([more](https://github.com/richpeck/exception_handler/wiki/1-Setup))
360
- - [x] Rails asset management improvement
361
- - [x] Reduced gem file size
362
-
363
- ### [0.4.7](https://github.com/richpeck/exception_handler/releases/tag/0.4.6)
364
- - [x] New config system
365
- - [x] Fixed controller layout issues
366
- - [x] Streamlined middleware
367
- - [x] New layout & interface
368
-
369
- ----
370
-
371
- [![404 + 500 Errors][banner]][rubygems]
372
-
373
- <p align="center">
374
- <strong><a href="#">ExceptionHandler</a> is now the leading custom error pages gem for Rails.</strong>
375
- <br />
376
- No other gem is as simple or effective at providing beautiful exception pages in production.
377
- </p>
378
-
379
- <p align="center">
380
- <a href="http://badge.fury.io/rb/exception_handler"><img src="https://badge.fury.io/rb/exception_handler.svg" align="absmiddle"></a>
381
- <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>
382
- <a href="https://codeclimate.com/github/richpeck/exception_handler"><img src="https://codeclimate.com/github/richpeck/exception_handler/badges/gpa.svg" align="absmiddle"/></a>
383
- <a href="https://gemnasium.com/richpeck/exception_handler"><img src="https://gemnasium.com/richpeck/exception_handler.svg" align="absmiddle"></a>
384
- <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>
385
- <a href="https://travis-ci.org/richpeck/exception_handler"><img src="https://travis-ci.org/richpeck/exception_handler.svg?branch=master" align="absmiddle"></a>
386
- </p>
387
-
388
- <p align="center">
389
- <strong><a href="https://rubygems.org/gems/exception_handler">Download Here</a></strong>
390
- </p>
391
-
392
- ----------
393
-
394
- :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>
395
-
396
- <!-- ################################### -->
397
- <!-- ################################### -->
398
-
399
- <!-- Refs -->
400
- <!-- Comments http://stackoverflow.com/a/20885980/1143732 -->
401
- <!-- Images https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#images -->
402
-
403
- <!-- Images -->
404
- [dev_mode]: readme/dev_mode.jpg
405
- [dev_img]: readme/dev.png
406
- [layouts_img]: readme/layouts.jpg
407
- [layout_img]: readme/layout.png
408
- [view_img]: readme/view.jpg
409
- [http_codes]: readme/http_codes.png
410
- [config]: readme/config.jpg
411
- [config.action_dispatch.rescue_responses]: readme/config.action_dispatch.rescue_responses.jpg
412
- [banner]: readme/banner.jpg
413
- [gem]: readme/gem.jpg
414
- [gemfile]: readme/gemfile.jpg
415
- [middleware]: readme/middleware.jpg
416
- [exceptions_app]: readme/exceptions_app.jpg
417
- [view]: readme/titles/view.jpg
418
- [dev]: readme/titles/dev.jpg
419
- [db]: readme/titles/db.png
420
- [support]: readme/titles/support.png "Support"
421
- [changelog]: readme/titles/changelog.png "Changelog"
422
- [contribution]: readme/titles/contributions.png "Contributions"
423
- [fl]: readme/fl.jpg "Frontline Utilities LTD"
424
- [profile]: https://avatars0.githubusercontent.com/u/1104431 "R Peck"
425
-
426
- <!-- Links -->
427
- [better_errors]: https://github.com/charliesome/better_errors
428
- [layout]: app/views/layouts/exception.html.erb
429
- [status_codes]: http://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option
430
- [stackoverflow]: http://stackoverflow.com/questions/ask?tags=ruby-on-rails+exception-handler
431
- [rescue_responses]: http://guides.rubyonrails.org/configuring.html#configuring-action-dispatch
432
- [latest]: https://github.com/richpeck/exception_handler/releases/latest
433
- [show_exception]: https://github.com/rails/rails/blob/4-0-stable/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
434
- [exception_app]: http://guides.rubyonrails.org/configuring.html#rails-general-configuration
435
- [rubygems]: http://rubygems.org/gems/exception_handler
436
- [frontlineutilities.co.uk]: http://www.frontlineutilities.co.uk
437
- [stackoverflow.com]: http://stackoverflow.com/users/1143732/richard-peck?tab=profile
438
- [fork]: #fork-destination-box
439
- [pull]: http://github.com/richpeck/exception_handler/pulls
440
- [issues]: http://github.com/richpeck/exception_handler/issues
441
-
442
- <!-- ################################### -->
443
- <!-- ################################### -->
1
+ ![Exception Handler](readme/title.jpg "Exception Handler Logo")
2
+
3
+ <!-- Intro -->
4
+ <div id="intro">
5
+ <h4 align="center"><code><strong><a href="https://www.github.com/richpeck/exception_handler">ExceptionHandler</a></strong></code> is presently the MOST POPULAR exceptions gem for <a href="https://medium.com/ruby-on-rails-web-application-development/custom-400-500-error-pages-in-ruby-on-rails-exception-handler-3a04975e4677">CUSTOM Rails error pages</a>.</h4>
6
+ <p align="center">
7
+ With <strong>290,000+ downloads</strong>, it is the *only* gem to provide <strong>custom 400/500 exception pages for Rails 5 & 6</strong>
8
+ </p>
9
+ <p><img src="./readme/dev.png" /></p>
10
+ <h4 align="center">Current <a href="https://github.com/richpeck/exception_handler/releases"><u>0.8.0.0</u></a> (August 2018)</h4>
11
+ </div>
12
+
13
+ <!-- Badges -->
14
+ <p align="center">
15
+ <a href="http://badge.fury.io/rb/exception_handler"><img src="https://badge.fury.io/rb/exception_handler.svg" align="absmiddle"></a>
16
+ <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>
17
+ <a href="https://codeclimate.com/github/richpeck/exception_handler"><img src="https://codeclimate.com/github/richpeck/exception_handler/badges/gpa.svg" align="absmiddle"/></a>
18
+ <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>
19
+ <a href="https://travis-ci.org/richpeck/exception_handler"><img src="https://travis-ci.org/richpeck/exception_handler.svg?branch=master" align="absmiddle"></a>
20
+ </p>
21
+
22
+ <!-- Navigation -->
23
+ <div id="navigation">
24
+ <p align="center"><img src="https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png" width="100%" /></p>
25
+ <p align="center">
26
+ <strong>
27
+ 📝 <a href="#introduction">Introduction</a> -
28
+ ⚠️ <a href="#installation">Installation</a> -
29
+ 🔧 <a href="#configuration">Configuration</a> -
30
+ ☎️ <a href="#support">Support</a> -
31
+ ⭐ <a href="#changelog">Changelog</a>
32
+ </strong>
33
+ </p>
34
+ <p align="center"><img src="https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png" width="100%" /></p>
35
+ </div>
36
+
37
+ <!-- Introduction -->
38
+ <div id="introduction">
39
+ <h4>📝 Introduction</h4>
40
+ </div>
41
+
42
+ ---
43
+ <div>
44
+ <p><b><code>ExceptionHandler</b></code> replaces Rails' default error pages with <strong>dynamic views</strong>.</p>
45
+ <p>It does this by injecting <a href="https://guides.rubyonrails.org/configuring.html#rails-general-configuration"><code>config.exceptions_app</code></a> with our controller - allowing us to populate erroneous responses with our own HTML. To understand how this works, you need to appreciate how Rails handles errors:</p>
46
+ <p align="center"><a href="https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/show_exceptions.rb#L44"><img src="readme/show_exceptions.png" width="550"></a></p>
47
+ <p>Rails uses <a href="https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/show_exceptions.rb"><code><strong>ActionDispatch::ShowExceptions</strong></code></a> (above) to generate error responses.</p>
48
+ <p>Because web browsers (Rails is a web framework) can only interpret <a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Response_message">HTTP responses</a>, Ruby/Rails exceptions have to be translated into something a browser can read. This is done by calling the above middleware.</p>
49
+ <p>--</p>
50
+ <p>As highlighted, an HTTP response is built independent of the Rails stack. This includes assigning an HTTP status code and HTML response body. It's the response body which <code><strong>ExceptionHandler</strong></code> is designed to override.</p>
51
+ </div>
52
+
53
+ <!-- Sep -->
54
+ <p align="center">
55
+ <img src="https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png" width="100%" />
56
+ </p>
57
+
58
+ <!-- Installation -->
59
+ <div id="installation">
60
+ <h4>⚠️ Installation</h4>
61
+ </div>
62
+
63
+ ---
64
+
65
+ <div>
66
+ <p>
67
+ 💎 <u><a href="https://rubygems.org/gems/exception_handler">RubyGems</a></u> (Code) |
68
+ 💻 <u><a href="https://medium.com/ruby-on-rails-web-application-development/custom-400-500-error-pages-in-ruby-on-rails-exception-handler-3a04975e4677">Medium</a></u> (Tutorial)
69
+ </p>
70
+ <pre><code># Gemfile
71
+ gem 'exception_handler', '~> 0.8.0.0'</code></pre>
72
+ <p>Because <b>ExceptionHandler</b> is built around a Rails engine, there is <b>nothing</b> to be done to get it working in production. Installing the Gem <b><i>should</i></b> translate your production 4xx/5xx error pages into dynamic views.</p>
73
+ <p>Environments <u>other</u> than production (development/staging) required the <a href="#dev"><code>dev</code></a> variable to be <code>true</code>.</p>
74
+ </div>
75
+
76
+ <!-- Sep -->
77
+ <p align="center">
78
+ <img src="https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png" width="100%" />
79
+ </p>
80
+
81
+ <!-- configuration -->
82
+ <div id="configuration">
83
+ <h4>🔧 Configuration</h4>
84
+ </div>
85
+
86
+ ---
87
+
88
+ <p align="center">
89
+ <g-emoji class="g-emoji" alias="file_folder" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4c1.png">📁</g-emoji> <a href="#config">Config</a>&nbsp;&nbsp;&nbsp;&nbsp;<g-emoji class="g-emoji" alias="computer" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4bb.png">💻</g-emoji> <a href="#dev" title="Dev Mode">Dev</a>&nbsp;&nbsp;&nbsp;&nbsp;<g-emoji class="g-emoji" alias="floppy_disk" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4be.png">💾</g-emoji> <a href="#db">Database</a>&nbsp;&nbsp;&nbsp;&nbsp;<g-emoji class="g-emoji" alias="email" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2709.png">✉️</g-emoji> <a href="#email">Email</a>&nbsp;&nbsp;&nbsp;&nbsp;<g-emoji class="g-emoji" alias="eyeglasses" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f453.png">👓</g-emoji> <a href="#views">Views</a>&nbsp;&nbsp;&nbsp;&nbsp;<g-emoji class="g-emoji" alias="speech_balloon" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4ac.png">💬</g-emoji> <a href="#locales">Locales</a>&nbsp;&nbsp;&nbsp;&nbsp;<g-emoji class="g-emoji" alias="clipboard" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4cb.png">📋</g-emoji> <a href="#layouts">Layouts</a>&nbsp;&nbsp;&nbsp;&nbsp;<g-emoji class="g-emoji" alias="no_entry" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/26d4.png">⛔️</g-emoji> <a href="#custom-exceptions">Custom Exceptions</a>
90
+ </p>
91
+
92
+ ---
93
+
94
+ <!-- Config -->
95
+ <a name="config"></a>
96
+
97
+ The **ONLY** thing you need to manage `ExceptionHandler` is its [`config`](https://github.com/richpeck/exception_handler/blob/master/lib/exception_handler/config.rb) settings.
98
+
99
+ Whilst the gem **works out of the box** (without any configuration), if you want to manage the [`layouts`](#layouts), [`email`](#email), [`dev`](#dev) or the [`database`](#db), you'll need to set the appropriate values in the config hash.
100
+
101
+ This is done in `config/application.rb` or `config/environments/[env].rb`
102
+
103
+ ```rb
104
+ # config/application.rb
105
+
106
+ module YourApp
107
+ class Application < Rails::Application
108
+
109
+ # => This is an example of ALL available config options
110
+ # => You're able to see exactly how it works here:
111
+ # => https://github.com/richpeck/exception_handler/blob/master/lib/exception_handler/config.rb
112
+
113
+ # => Config hash (no initializer required)
114
+ config.exception_handler = {
115
+ dev: nil, # allows you to turn ExceptionHandler "on" in development
116
+ db: nil, # allocates a "table name" into which exceptions are saved (defaults to nil)
117
+ email: nil, # sends exception emails to a listed email (string // "you@email.com")
118
+
119
+ # Custom Exceptions
120
+ custom_exceptions: {
121
+ #'ActionController::RoutingError' => :not_found # => example
122
+ },
123
+
124
+ # On default 5xx error page, social media links included
125
+ social: {
126
+ facebook: nil, # Facebook page name
127
+ twitter: nil, # Twitter handle
128
+ youtube: nil, # Youtube channel name / ID
129
+ linkedin: nil, # LinkedIn name
130
+ fusion: nil # FL Fusion handle
131
+ },
132
+
133
+ # This is an entirely NEW structure for the "layouts" area
134
+ # You're able to define layouts, notifications etc ↴
135
+
136
+ # All keys interpolated as strings, so you can use symbols, strings or integers where necessary
137
+ exceptions: {
138
+
139
+ :all => {
140
+ layout: "exception", # define layout
141
+ notification: true, # (false by default)
142
+ deliver: #something here to control the type of response
143
+ },
144
+ :4xx => {
145
+ layout: nil, # define layout
146
+ notification: true, # (false by default)
147
+ deliver: #something here to control the type of response
148
+ },
149
+ :5xx => {
150
+ layout: "exception", # define layout
151
+ notification: true, # (false by default)
152
+ deliver: #something here to control the type of response
153
+ },
154
+ 500 => {
155
+ layout: "exception", # define layout
156
+ notification: true, # (false by default)
157
+ deliver: #something here to control the type of response
158
+ },
159
+
160
+ # This is the old structure
161
+ # Still works but will be deprecated in future versions
162
+
163
+ 501 => "exception",
164
+ 502 => "exception",
165
+ 503 => "exception",
166
+ 504 => "exception",
167
+ 505 => "exception",
168
+ 507 => "exception",
169
+ 510 => "exception"
170
+
171
+ }
172
+ }
173
+ end
174
+ end
175
+ ```
176
+
177
+ For a full retinue of the available options, you'll be best looking at the [`config`](https://github.com/richpeck/exception_handler/blob/master/lib/exception_handler/config.rb) file itself.
178
+
179
+ --
180
+
181
+ If using an [`engine`](http://guides.rubyonrails.org/engines.html), you **DON'T need an `initializer`**:
182
+ ```rb
183
+ # lib/engine.rb
184
+ module YourModule
185
+ class Engine < Rails::Engine
186
+
187
+ # => ExceptionHandler
188
+ # => Works in and out of an initializer
189
+ config.exception_handler = {
190
+ dev: nil, # => this will not load the gem in development
191
+ db: true # => this will use the :errors table to store exceptions
192
+ }
193
+ end
194
+ end
195
+ ```
196
+
197
+ The best thing about using a `config` options block is that you are able to only define the options that you require.
198
+
199
+ If you have particular options you *only* wish to run in `staging`, or have single options for `production` etc, this setup gives you the ability to manage it properly...
200
+
201
+ ---
202
+
203
+ <!-- Dev -->
204
+ <div id="dev">
205
+ <h5>💻 Dev</h5>
206
+ </div>
207
+
208
+ As explained, `ExceptionHandler` does *not* work in `development` by default.
209
+
210
+ This is because it overrides the `exceptions_app` middleware hook - which is *only* invoked in `production` or `staging`.
211
+
212
+ <p align="center">
213
+ <img src="./readme/dev.png" />
214
+ </p>
215
+
216
+ To get it working in `development`, you need to override the [`config.consider_all_requests_local`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration) setting (a standard component of Rails) - setting it to "false" ↴
217
+
218
+ <p align="center">
219
+ <img src="./readme/local_requests.jpg" />
220
+ </p>
221
+
222
+ This is normally done by changing the setting in your Rails config files. However, to make the process simpler for `ExceptionHandler`- we've added a `dev` option which allows you to override the hook through the context of the gem...
223
+
224
+ ```rb
225
+ # config/application.rb
226
+ config.exception_handler = { dev: true }
227
+ ```
228
+
229
+ This disables [`config.consider_all_requests_local`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration), making Rails behave as it would in production.
230
+
231
+ Whilst simple, it's not recommended for extended use. Very good for testing new ideas etc.
232
+
233
+ ---
234
+
235
+ <!-- DB -->
236
+ <div id="db">
237
+ <h5>💾 DB</h5>
238
+ </div>
239
+
240
+ To save exceptions to your database, you're able to set the `db` option.
241
+
242
+ Because we use a `controller` to manage the underlying way the system works, we're able to invoke the likes of a [`model`](https://github.com/richpeck/exception_handler/blob/master/app/models/exception_handler/exception.rb) with other functionality.
243
+
244
+ Ths is done automatically with the latest version of `ExceptionHandler`.
245
+
246
+ To do this, once you've populated the option with either `true` or a `string`, run `rails db:migrate` from your console.
247
+
248
+ Our new [`migration system`](https://github.com/richpeck/exception_handler/tree/readme#migrations) will automatically run the migration.
249
+
250
+ ```rb
251
+ # config/application.rb
252
+ config.exception_handler = { db: true }
253
+ ```
254
+
255
+ This enables `ActiveRecord::Base` on the [`Exception`](app/models/exception_handler/exception.rb) class, allowing us to save to the database.
256
+
257
+ In order for this to work, your db needs the correct table.
258
+
259
+ ---
260
+
261
+ <!-- Email -->
262
+ <div id="email">
263
+ <h5>✉️ Email</h5>
264
+ </div>
265
+
266
+ `ExceptionHandler` also sends **email notifications**.
267
+
268
+ If you want to receive emails whenever your application raises an error, you can do so by adding your email to the config:
269
+
270
+ ```rb
271
+ # config/application.rb
272
+ config.exception_handler = {
273
+ email: "your@email.com"
274
+ }
275
+ ```
276
+
277
+ > **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.
278
+
279
+ From version [`0.8.0.0`](https://github.com/richpeck/exception_handler/releases/tag/v0.8.0.0), you're able to define whether email notifications are sent on a per-error basis:
280
+
281
+ ```rb
282
+ # config/application.rb
283
+ config.exception_handlder = {
284
+
285
+ # This has to be present for any "notification" declarations to work
286
+ # Defaults to 'false'
287
+ email: "test@test.com",
288
+
289
+ # Each status code in the new "exceptions" block allows us to define whether email notifications are sent
290
+ exceptions: {
291
+ :all => { notification: true },
292
+ :50x => { notification: false },
293
+ 500 => { notification: false }
294
+ }
295
+ }
296
+ ```
297
+ ---
298
+
299
+ <!-- Views -->
300
+ <div id="views">
301
+ <h5>👓 Views</h5>
302
+ </div>
303
+
304
+ What *most* people want out of the view is to change the way it ***looks***. This can be done without changing the "view" itself.
305
+
306
+ To better explain, if [`ExceptionsController`](https://github.com/richpeck/exception_handler/blob/master/app/controllers/exception_handler/exceptions_controller.rb) is invoked (by `exceptions_app`), it has **ONE** method ([`show`](https://github.com/richpeck/exception_handler/blob/master/app/controllers/exception_handler/exceptions_controller.rb#L42)).
307
+
308
+ This method calls the [`show` view](https://github.com/richpeck/exception_handler/blob/master/app/views/exception_handler/exceptions/show.html.erb), which is *entirely* dependent on the locales for content & the layout for the look.
309
+
310
+ This means that if you wish to change how the view "looks" - you're *either* going to want to change your [layout][layouts] or the [*locales*](#locales). There is NO reason to change the `show` view itself - it's succinct and entirely modular. Whilst you're definitely at liberty to change it, you'll just be making the issue more complicated than it needs to be.
311
+
312
+ --
313
+
314
+ We've also included a number of routes which shows in [`dev`](dev) mode (allowing you to test):
315
+
316
+ <p align="center">
317
+ <img src="./readme/routes.jpg" />
318
+ </p>
319
+
320
+ ---
321
+
322
+ <!-- Locales -->
323
+ <div id="locales">
324
+ <h5>💬 Locales</h5>
325
+ </div>
326
+
327
+ [Locales](https://github.com/richpeck/exception_handler/blob/Readme/config/locales/exception_handler.en.yml) are used to create interchangeable text (translations/internationalization).
328
+
329
+ --
330
+
331
+ In `ExceptionHandler`, it provides the wording for each type of error code.
332
+
333
+ By default, the English name of the error is used (`"404"` will appear as `"Not Found"`) - if you want to create custom messages, you're able to do so by referencing the error's ["status_code"](https://github.com/rack/rack/blob/master/lib/rack/utils.rb#L492) within your locales file:
334
+
335
+ ```yml
336
+ # config/locales/en.yml
337
+ en:
338
+ exception_handler:
339
+ not_found: "Your message here" # -> 404 page
340
+ unauthorized: "You need to login to continue"
341
+ internal_server_error: "This is a test to show the %{status} of the error"
342
+ ```
343
+
344
+ You get access to [`%{message}` and `%{status}`](https://github.com/richpeck/exception_handler/blob/master/app/views/exception_handler/exceptions/show.html.erb#L1), both inferring from an [`@exception`](https://github.com/richpeck/exception_handler/blob/master/app/controllers/exception_handler/exceptions_controller.rb#L20) object we invoke in the controller...
345
+
346
+ - `%{message}` is the error's actual message ("XYZ file could not be shown")
347
+ - `%{status}` is the error's status code ("Internal Server Error")
348
+
349
+ --
350
+
351
+ By default, only `internal_server_error` is customized by the gem:
352
+
353
+ ```yml
354
+ # config/locales/en.yml
355
+ en:
356
+ exception_handler:
357
+ internal_server_error: "<strong>%{status} Error</strong> %{message}"
358
+ ```
359
+ ---
360
+
361
+ <!-- Layouts -->
362
+ <div id="layouts">
363
+ <h5>📋 Layouts</h5>
364
+ </div>
365
+
366
+ The most attractive feature of `ExceptionHandler` (for most) is its ability to manage [`layouts`](https://guides.rubyonrails.org/layouts_and_rendering.html#structuring-layouts) for HTTP status.
367
+
368
+ --
369
+
370
+ The reason for this is due to the way in which Rails works → the "layout" is a "wrapper" for the returned HTML (the "styling" of a page). If you have no layout, it will render the "view" HTML and nothing else.
371
+
372
+ This means if you want to change the "look" of a Rails action, you simply have to be able to change the `layout`. You should not change the view at all.
373
+
374
+ To this end, `ExceptionHandler` has been designed around providing a [SINGLE VIEW](app/controllers/exception_handler/exceptions_controller.rb#L44) for exceptions. This view does not need to change (although you're welcome to use a [`generator`][generators] to do so) - the key is the `layout` that's assigned...
375
+
376
+ - [`4xx`](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_errors) errors are given a `nil` layout (by default) (inherits from `ApplicationController` in your main app)
377
+ - [`5xx`](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_errors) errors are assigned our own [`exception`](app/views/layouts/exception.html.erb) layout:
378
+
379
+ ```rb
380
+ # config/application.rb
381
+ config.exception_handler = {
382
+
383
+ # The new syntax allows us to assign different values to each HTTP status code
384
+ # At the moment, only 'layout' & 'notification' are supported
385
+ # We plan to include several more in the future...
386
+
387
+ exceptions: {
388
+ all: { layout: nil } # -> this will inherit from ApplicationController's layout
389
+ }
390
+ }
391
+ ```
392
+
393
+ The `layout` system has changed between [`0.7.7.0`](releases/tag/v0.7.7.0) and [`0.8.0.0`](releases/tag/v0.8.0.0).
394
+
395
+ Building on the former's adoption of HTTP status-centric layouts, it is now the case that we have the `all`, `5xx` and `4xx` options - allowing us to manage the layouts for blocks of HTTP errors respectively:
396
+
397
+ ```rb
398
+ # config/application.rb
399
+ config.exception_handler = {
400
+
401
+ # Old (still works)
402
+ # No "all" / "4xx"/"5xx" options
403
+ layouts: {
404
+ 500 => 'exception',
405
+ 501 => 'exception'
406
+ },
407
+
408
+ # New
409
+ exceptions: {
410
+ :all => { layout: 'exception' },
411
+ :4xx => { layout: 'exception' },
412
+ :5xx => { layout: 'exception' }, # -> this overrides the :all declaration
413
+ 500 => { layout: nil } # -> this overrides the 5xx declaration
414
+ }
415
+ }
416
+ ```
417
+
418
+ We've bundled the [`exception`](app/views/layouts/exception.html.erb) layout for `5xx` errors because since these denote internal server errors, it's best to isolate the view system as much as possible. Whilst you're at liberty to change it, we've found it sufficient for most use-cases.
419
+
420
+ ---
421
+
422
+ <!-- Custom Exceptions -->
423
+ <div id="custom-exceptions">
424
+ <h5>⛔️ Custom Exceptions</h5>
425
+ </div>
426
+
427
+ As mentioned, Rails' primary role is to convert Ruby exceptions into HTTP errors.
428
+
429
+ Part of this process involves mapping Ruby/Rails exceptions to the equivalent HTTP status code.
430
+
431
+ This is done with [`config.action_dispatch.rescue_responses`](https://github.com/rack/rack/blob/master/lib/rack/utils.rb#L492).
432
+
433
+ <p align="center">
434
+ <img src="./readme/custom_exceptions.png" />
435
+ </p>
436
+
437
+ Whilst this works well, it may be the case that you want to map your own classes to an HTTP status code (default is `Internal Server Error`).
438
+
439
+ If you wanted to keep this functionality inside `ExceptionHandler`, you're able to do it as follows:
440
+
441
+ ```rb
442
+ # config/application.rb
443
+ config.exception_handler = {
444
+ custom_exceptions: {
445
+ 'CustomClass::Exception' => :not_found
446
+ }
447
+ }
448
+ ```
449
+
450
+ Alternatively, you're able to still do it with the default Rails behaviour:
451
+
452
+ ```rb
453
+ # config/application.rb
454
+ config.action_dispatch.rescue_responses = { 'CustomClass::Exception' => :not_found }
455
+ ```
456
+ ---
457
+
458
+ <!-- Generators -->
459
+ <div id="generators">
460
+ <h5>💼 Generators</h5>
461
+ </div>
462
+
463
+ If you want to edit the `controller`, `views`, `model` or `assets`, you're able to invoke them in your own application.
464
+
465
+ This is done - as with other gems - with a single [`generator`](https://github.com/richpeck/exception_handler/blob/master/lib/generators/exception_handler/views_generator.rb) which takes a series of arguments:
466
+
467
+ rails g exception_handler:views
468
+ rails g exception_handler:views -v views
469
+ rails g exception_handler:views -v controllers
470
+ rails g exception_handler:views -v models
471
+ rails g exception_handler:views -v assets
472
+ rails g exception_handler:views -v views controllers models assets
473
+
474
+ If you don't include any switches, this will copy **all** `ExceptionHandler`'s folders put into your app.
475
+
476
+ Each switch defines which folders you want (EG `-v views` will only copy `views` dir).
477
+
478
+ ---
479
+
480
+ <!-- Migrations -->
481
+ <div id="migrations">
482
+ <h5>✔️ Migrations</h5>
483
+ </div>
484
+
485
+ You **DON'T** need to generate a migration anymore.
486
+
487
+ 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).
488
+
489
+ The reason we did this was so not to pollute your migrations folder with a worthless file. Our migration doesn't need to be changed - we only have to get it into the database and the gem takes care of the rest...
490
+
491
+ > If you set the [`db`][db] option in config, run `rails db:migrate` and the migration will be run.
492
+
493
+ To rollback, use the following:
494
+
495
+ rails db:migrate:down VERSION=000000
496
+
497
+ The drawback to this is that if you remove `ExceptionHandler` before you rollback the migration, it won't exist anymore.
498
+
499
+ You can **only** fire the `rollback` when you have `ExceptionHandler` installed.
500
+
501
+ <!-- Sep -->
502
+ <p align="center">
503
+ <img src="https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png" width="100%" />
504
+ </p>
505
+
506
+ <!-- Support-->
507
+ <div id="support">
508
+ <h4>☎️ Support</h4>
509
+ </div>
510
+
511
+ ---
512
+
513
+ <div>
514
+ <p>You're welcome to contact me directly at <u><a href="mailto:rpeck@frontlineutilities.co.uk"></a><a href="mailto:rpeck@frontlineutilities.co.uk" ref="nofollow">rpeck@frontlineutilities.co.uk</a></u>.</p>
515
+ <p>Alternatively, you may wish to post on our <u><a href="https://github.com/richpeck/exception_handler/issues">GitHub Issues</a></u>, or <u><a href="https://stackoverflow.com/questions/tagged/ruby-on-rails+exceptionhandler" rel="nofollow">StackOverflow</a></u>.</p>
516
+ <p>--</p>
517
+ <p><a href="https://medium.com/ruby-on-rails-web-application-development/custom-400-500-error-pages-in-ruby-on-rails-exception-handler-3a04975e4677" rel="nofollow"><img src="readme/medium.png" target="_blank" alt="Medium" style="max-width:100%;"></a></p>
518
+ </div>
519
+
520
+ <!-- Sep -->
521
+ <p align="center">
522
+ <img src="https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png" width="100%" />
523
+ </p>
524
+
525
+ <!-- Changelog -->
526
+ <div id="changelog">
527
+ <h4>⭐ Changelog</h4>
528
+ </div>
529
+
530
+ ---
531
+
532
+ [**1.0.0.0**](https://github.com/richpeck/exception_handler/releases/tag/v1.0.0.0)
533
+ - [ ] TBA
534
+
535
+ [**0.8.0.0**](https://github.com/richpeck/exception_handler/releases/tag/v0.8.0.0)
536
+ - [x] [README](https://github.com/richpeck/exception_handler/issues/52) (focus on utility)
537
+ - [x] Introduction of `4xx`,`5xx`,`:all` for layouts config
538
+ - [x] Changed `layouts` to `exceptions` in config
539
+ - [x] Email improvement
540
+ - [x] Streamlined migration
541
+ - [x] Updated model
542
+
543
+ [**0.7.7.0**](https://github.com/richpeck/exception_handler/releases/tag/v0.7.7.0)
544
+ - [x] [HTTP status layouts](#layouts)
545
+
546
+ **0.7.0.0**
547
+ - [x] Wildcard mime types
548
+ - [x] [Custom exceptions](#custom_exceptions)
549
+ - [x] Test suite integration
550
+ - [x] [Model backend](#database)
551
+ - [x] Sprockets 4+
552
+ - [x] New layout
553
+ - [x] Readme / wiki overhaul
554
+
555
+ **0.6.5.0**
556
+ - [x] Streamlined interface
557
+ - [x] ActiveRecord / Middleware overhaul
558
+ - [x] Supports Sprockets 4+ ([`manifest.js`](http://eileencodes.com/posts/the-sprockets-4-manifest/))
559
+ - [x] Email integration
560
+ - [x] Asset overhaul & improvement
561
+ - [x] Removed dependencies
562
+
563
+ **0.5.0.0**
564
+ - [x] Locales
565
+ - [x] Email notifications
566
+ - [x] Full test suite
567
+ - [x] Rails 4.2 & Rails 5.0 native ([`request.env`](https://github.com/rails/rails/commit/05934d24aff62d66fc62621aa38dae6456e276be) fix)
568
+ - [x] Controller fixed
569
+ - [x] `DB` fixed
570
+ - [x] Legacy initializer support ([more](https://github.com/richpeck/exception_handler/wiki/1-Setup))
571
+ - [x] Rails asset management improvement
572
+ - [x] Reduced gem file size
573
+
574
+ **0.4.7.0**
575
+ - [x] New config system
576
+ - [x] Fixed controller layout issues
577
+ - [x] Streamlined middleware
578
+ - [x] New layout & interface
579
+
580
+ <!-- Sep -->
581
+ <p align="center">
582
+ <img src="https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png" width="100%" />
583
+ </p>
584
+
585
+ [![404 + 500 Errors][banner]][rubygems]
586
+
587
+ <p align="center">
588
+ <strong><a href="https://rubygems.org/gems/exception_handler"><code>ExceptionHandler</code></a> provides custom error pages gem for Rails 5+</strong>
589
+ <br />
590
+ No other gem is as simple or effective at providing branded exception pages in production
591
+ </p>
592
+
593
+ <p align="center">
594
+ <a href="http://badge.fury.io/rb/exception_handler"><img src="https://badge.fury.io/rb/exception_handler.svg" align="absmiddle"></a>
595
+ <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>
596
+ <a href="https://codeclimate.com/github/richpeck/exception_handler"><img src="https://codeclimate.com/github/richpeck/exception_handler/badges/gpa.svg" align="absmiddle"/></a>
597
+ <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>
598
+ <a href="https://travis-ci.org/richpeck/exception_handler"><img src="https://travis-ci.org/richpeck/exception_handler.svg?branch=master" align="absmiddle"></a>
599
+ </p>
600
+
601
+ <p align="center">
602
+ <strong>➡️ <a href="https://rubygems.org/gems/exception_handler">Download & Info</a> ⬅️</strong>
603
+ </p>
604
+
605
+ <!-- Sep -->
606
+ <p align="center">
607
+ <img src="https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png" width="100%" />
608
+ </p>
609
+
610
+ :copyright: <a href="http://www.fl.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> <a href="https://github.com/joehilton" align="absmiddle" ><img src="https://avatars2.githubusercontent.com/u/5063592?s=460&v=4" height="22" align="absmiddle" /></a> <a href="https://github.com/toymachiner62" align="absmiddle" ><img src="https://avatars3.githubusercontent.com/u/485782" height="22" align="absmiddle" /></a> <a href="https://github.com/andrewclink" align="absmiddle" ><img src="https://avatars0.githubusercontent.com/u/688916" height="22" align="absmiddle" /></a> <a href="https://github.com/Startouf" align="absmiddle" ><img src="https://avatars2.githubusercontent.com/u/7388889" height="22" align="absmiddle" /></a> <a href="https://github.com/Tonkonozhenko" align="absmiddle" ><img src="https://avatars0.githubusercontent.com/u/1307646" height="22" align="absmiddle" /></a> <a href="https://github.com/mabako" align="absmiddle" ><img src="https://avatars3.githubusercontent.com/u/125113" height="22" align="absmiddle" /></a> <a href="https://github.com/frankzhao" align="absmiddle" ><img src="https://avatars3.githubusercontent.com/u/555499" height="22" align="absmiddle" /></a>
611
+
612
+
613
+ <!-- ################################### -->
614
+ <!-- ################################### -->
615
+
616
+ <!-- Refs -->
617
+ <!-- Comments http://stackoverflow.com/a/20885980/1143732 -->
618
+ <!-- Images https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#images -->
619
+
620
+ <!-- Images -->
621
+ [banner]:readme/banner.jpg
622
+
623
+ <!-- Links -->
624
+ [rubygems]: http://rubygems.org/gems/exception_handler
625
+
626
+ [10x]: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#1xx_Informational_responses
627
+ [20x]: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success
628
+ [30x]: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection
629
+ [40x]: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_errors
630
+ [50x]: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_errors
631
+
632
+ <!-- Local Links -->
633
+ [db]: #db
634
+ [email]: #email
635
+ [dev]: #dev
636
+ [layouts]: #layouts
637
+ [locales]: #locales
638
+ [configuration]: #configuration
639
+ [generators]: #generators
640
+ [custom-exceptions]: #custom-exceptions
641
+
642
+ <!-- ################################### -->
643
+ <!-- ################################### -->