
Custom 404 & 500 production error pages for Rails 4 & 5.

Responsive
Branded Error Pages
Middleware Exception Handling
Fully Customizable
New Controller
New Middleware
Full Test Suite
Fully Rails 4 & 5 Compatible
Brand new controller & middleware have made ExceptionHandler even more powerful & efficient. Now you can use ExceptionHandler with a single click → plug and play custom exception pages:
With major upgrades to the backend, ExceptionHandler 0.7.0 is the leading exception management solution for Rails 5:
Features
Custom 500 Errors Layout || DB || Model || Config || Email || 400 Default Layout || Sprockets 4 || Custom ExceptionsExceptionHandler works 100% with Rails 5 and Sprockets 4. It hooks DIRECTLY into your existing CSS to create a professional exception interface with NO work on your part…
The secret lies in config.exceptions_app ↴

Because we handle requests directly (message, details, user agent), ExceptionHandler populates our custom view with any details required. This gives us the ability to maintain your branding (layout / css) even when exceptions are raised:

This is important at is means ExceptionHandler has absolutely ZERO bloat on an app. Rails is invoked ONCE (not twice like it is when using routes), delivering a response JUST LIKE if an exception wasn't raised.
The ONLY professional solution to catch, process & handle Rails exceptions WITHOUT BLOAT:
The REAL beauty of ExceptionHandler is that you only have to serve two error responses → 400 & 500. This is per the HTTP spec - a browser CANNOT read any other form of error.
This means that we can use a single controller action to build our @exception object, responding to the HTTP request with the status code raised by the exception. We have built this into a simple & effective solution:
ExceptionHandler's config system stores the - you just need to install the gem & let it run.
If you want to change any settings (detailed below), you simply need to change config/application.rb or config/environments/your_env.rb. The POWER of this new config system means you're able to deploy ExceptionHandler in the most unobtrusive, versatile way possible:
ExceptionHandler 0.7.0 has drastically improved our famous 1-click install.
Not only have we removed all the bloat, but our initialization process now relies on a single hook which will set all the config variables as required. This is stark difference to the myriad of poorly-designed gems which cause massive lag in your Rails initialization process. ExceptionHandler is now more streamlined than ever:
The MAGIC lies in the environment files.
Instead of dopey initializers (which slow the system down), you can just use the Rails config files to set environment-dependent options. This allows us to maximize performance without any of the overhead associated with old-fashioned gems.
IMPORTANT
If you're upgrading from >=
0.4.7, you need to remove yourexception_handlerinitializer.We've changed the load process to use Rails app config - you don't need the
exception_handlerinitializer any more
As can be seen inconfig, the following are all the options ExceptionHandler accepts:
# Defaults
DEFAULTS = {
dev: false, #-> defaults to "false" for dev mode
db: false, #-> defaults to :errors if true, else use "table_name" / :table_name
email: false, #-> requires string email and ActionMailer
social: {
facebook: { name: "frontline.utilities", url: "https://facebook.com" },
twitter: { name: "frontlineutils", url: "http://twitter.com" },
youtube: { name: "frontlineutils", url: "https://youtube.com/user" },
linkedin: { name: "frontline-utilities", url: "https://linkedin.com/company" },
fusion: { name: "flutils", url: "https://frontlinefusion.com" }
},
layouts: {
"400" => nil, # => inherits from "ApplicationController" layout
"500" => "exception"
},
}
You can apply any of the above defaults into one of the Rails environment files:
config/application.rbconfig/environments/development.rbconfig/environments/production.rbconfig/environments/staging.rb
The benefit of this is that it gives you the ability to customize ExceptionHandler for any of your environments. Contrary to a shitty initializer, you're able to sculpt the gem to work for YOU.

Want to test in the dev environment?
# config/application.rb
config.exception_handler = {
dev: true # -> Runs in development mode WITHOUT changing the app environment files
}

config.exceptions_app only works when you have config.consider_all_requests_local = true, which is true in development:
config.consider_all_requests_localis a flag. If true then any error will cause detailed debugging information to be dumped in theHTTPresponse, and theRails::Info controllerwill show the application runtime context in/rails/info/properties.Trueby default in development and test environments, and false in production mode. For finer-grained control, set this to false and implementlocal_request?in controllers to specify which requests should provide debugging information on errors.
If you wish to test ExceptionHandler in development, you'll have to use the dev: true option in your exception_handler config, or change config.consider_all_requests_local = true in config/development.rb.

One of the most critial aspects of ExceptionHandler is the custom Exception layout.
If you want to change the layout (for 500 error pages), you need to use the following:

You'll need to generate it into your application before being able to edit:

ExceptionHandler comes with its own inbuilt views & controller.
If you want to change it, you need to add the views into your app with the generator
$ rails generate exception_handler:views #-> controller, models, helpers, views & assets
$ rails generate exception_handler:views -v views controllers models helpers assets #-> remove as appropriate to install individual assets
--

ExceptionHandler uses exceptions#show -- located in app/views/exception_handler/show.html.erb designed to work for all exceptions.
By default, it is split for use with different layouts, data being available to both.
This works exactly the same as the other views in your app (IE the exceptions controller invokes the show action)

If you want to store exceptions in your db, you will need to set up a migration:
$ rails generate exception_handler:migration
$ rake db:migrate
You will also need to ensure your config db option is either true or "table_name":


IMPORTANT
ExceptionHandler's new config system isenvironmentagnostic.Where you declare your
dbsetting will change depending on your environmentIf you declare
dbinapplication.rb, it will be applicable for allenvironments; only declaring inproduction.rbwill set it for production only.
We offer support through GitHub and StackOverflow.
Whilst we can't guarantee response times, we are always eager to make sure ExceptionHandler is the most secure, robust and effective solution for Rails exception pages. You can use the links below to access support directly:
| Github (~1hr) | Stackoverflow (~24hrs) |
|---|---|
![]() |
![]() |
We use ExceptionHandler in production, so have a vested interest in keeping it running smoothly.
Current version is 0.7.0
Functionality remains consistent with previous releases, main difference will be the way in which they handle backend processes. 0.7.0 completely overhauled the backend, making the controller, model and middleware much more streamlined.
The biggest update for 0.7.0. has been the removal of most middleware, putting the entire system into a central class. This not only allows us to centralize the data structure, but also remove many files which didn't matter.
Here is a rundown of what's been implemented ↴
→ 0.7.0
- [ ] Wildcard mime types
- [ ] Custom exceptions
- [x] Test suite integration
- [ ] Exception "mapping" (choose which exceptions to handle)
- [x] Email
- [x] Model backend
- [x] Sprockets 4+
- [x] Readme / wiki overhaul
→ 0.6.5
- [x] Streamlined interface
- [x] ActiveRecord / Middleware overhaul
- [x] Supports Sprockets 4+ (
manifest.js) - [x] Email integration
- [x] Asset overhaul & improvement
- [x] Removed dependencies
→ 0.5.0
- [x] Added locales
- [x] Email notifications
- [x] Full test suite
- [x] Rails 4.2 & Rails 5.0 native (
request.envfix) - [x] Controller fixed
- [x]
DBfixed - [x] Legacy initializer support (more)
- [x] Rails asset management improvement
- [x] Reduced gem file
→ 0.4.6
- [x] New config system (more)
- [x] Fixed controller layout issues
- [x] Streamlined middleware
- [x] New layout & interface implementation





