Skip to content

Commit 861a651

Browse files
committed
Update
1 parent 42a1b98 commit 861a651

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@
4141

4242
---
4343
<div>
44-
<p>Rails ships with <u>static HTML error pages</u>:</p>
45-
<p><img src="readme/default.png" width="500"></p>
46-
<p>These have an <u>unprofessional</u> appeal. If you are running a Rails app as part of a mission critical offering, you need to ensure it is as congruent as possible. To do this, we created a "custom error pages" solution.</p>
47-
<p>In 2014, we extracted this into a gem called <U>ExceptionHandler</u>. This gem has become popular thanks to its ease-of-use and ability to integrate with Rails 5.0+. The following explains how it works.</p>
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>
4851
</div>
4952

5053
<!-- Sep -->
@@ -61,7 +64,7 @@
6164

6265
<div>
6366
<p>
64-
💎 <u><a href="https://rubygems.org/gems/exception_handler">RubyGems</a></u> |
67+
💎 <u><a href="https://rubygems.org/gems/exception_handler">RubyGems</a></u> (Code) |
6568
💻 <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)
6669
</p>
6770
<pre><code># Gemfile

0 commit comments

Comments
 (0)