diff --git a/.gitignore b/.gitignore
index e492f373..6c2dc11a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,6 +21,7 @@ tmp
*.a
mkmf.log
*.tmp
+.rspec_status
##########################################################
##########################################################
diff --git a/.rspec b/.rspec
new file mode 100644
index 00000000..bd5e0288
--- /dev/null
+++ b/.rspec
@@ -0,0 +1,3 @@
+--format progress
+--color
+--require spec_helper
diff --git a/.travis.yml b/.travis.yml
index 87fc2cde..176e6626 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,7 @@
+language: ruby
rvm:
- 2.2.4
- - 2.3.2
- - 2.4.0
+ - 2.3.7
+ - 2.4.4
+ - 2.5.1
- ruby-head
diff --git a/Gemfile b/Gemfile
index 37fcd5b7..a7f9b326 100644
--- a/Gemfile
+++ b/Gemfile
@@ -10,4 +10,7 @@ group :test do
gem 'coveralls', require: false
end
+# => Required for Windows
+gem 'tzinfo-data' if Gem.win_platform? # => TZInfo For Windows
+
###########################################
diff --git a/README.md b/README.md
index 741a559c..13192c51 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,15 @@
+![Exception Handler](readme/title.jpg "Exception Handler Logo")
+
- New README coming soon (with upgrade to underlying codebase).
+ ![](./readme/dev.png)
-![Exception Handler](readme/title.jpg "Exception Handler Logo")
+
+
+
- Custom 404 & 500 production error pages for Rails 4 & 5.
+ ➡️ ExceptionHandler
is a Custom Error Pages Gem
For Ruby on Rails ⬅️ - With 160,000+ downloads, it is one of the most
popular, robust & extensible exceptions management gems for Ruby on Rails 4 & 5+...
@@ -18,132 +22,227 @@
- Install → Setup → Support
+
+
----
-
- ![](readme/version.jpg)
+ Version 🏹 0.8.0.0
🏹 has now introduced a number of ⭐️ KEY UPGRADES ⭐️ including...
🚧 New Config Settings 🚧 ▪️ 💻 Custom Views Options 💻 ▪️ 💬 4xx
/5xx
Locales 💬...
-
Responsive
-
Branded Error Pages
-
Middleware Exception Handling
-
Fully Customizable
+
+
-
-
+
+ ⚠️ Tutorial shows how it works ⚠️
+
✉️ Support Email ✉️
+
----
+
+
+
-
+
----
-
-
+
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](#install) → **plug and play** custom exception pages:
+
+
+
![](https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png)
+
+
⌚️ Introduction ⌚️
+
+
![](https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png)
+
+
+➡️ [**`ExceptionHandler`**](https://rubygems.org/gems/exception_handler) ⬅️ was designed to replace Rails' error pages ([`400.html`, `422.html`, `500.html`](https://github.com/rails/rails/tree/ef0b05e78fb0b928c7ef48d3c365dc849af50305/railties/lib/rails/generators/rails/app/templates/public)) with dynamic views...
-
-
-
+
-For over 3 years, ExceptionHandler has provided production-level Rails exception handling for 4xx and 5xx errors:
+The gem inserts a custom [ `controller`](app/controllers/exception_handler/exceptions_controller.rb) into [`exceptions_app`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration), allowing us to render custom HTML for erroneous requests.
-![HTTP Error Codes][http_codes]
+The controller uses a *single* method/view to build a response to errors. This view remains the same for *every* exception; the ONLY change is the *[layout](/app/views/layouts/exception.html.erb)* - depending on the HTTP response being returned (`4xx`/`5xx`).
-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.
+The beauty lies in the *simplicity* through which this is achieved → rather than having many different elements, its SOLE focus is to provide different HTML responses via differing *layouts*. `ExceptionHandler` does this within the scope of [`ActionView`](http://guides.rubyonrails.org/action_view_overview.html), allowing for the use of `views`, `helpers` and `data` from the database.
-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.
+Gem works 100% out of the box in `production`, and has the option to be called in [`dev`](#dev) if necessary.
-Now you can try for yourself ...
+--
+### 📑 HTTP
-----
+The most important thing to understand is that *it doesn't matter* which errors Ruby/Rails raises - they *all* need to be wrapped in a [valid HTTP response](https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html). Due to the nature of HTTP, you only need to facilitate responses for [`4xx`](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_errors) - [`5xx`](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_errors).
-
-
-
-
-
-The secret lies in [**`config.exceptions_app`**][exception_app] ↴
+This means that all you're really doing is taking "Ruby" errors and giving them an appropriate [HTTP status code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) & [message body](https://en.wikipedia.org/wiki/HTTP_message_body) (HTML). Rails handles the process for you - the *only* thing we need to worry about is how the HTML is generated.
-> **`config.exceptions_app`** sets the exceptions application invoked by the **`ShowException`** middleware when an exception happens. Defaults to **`ActionDispatch::PublicExceptions.new(Rails.public_path)`**
+What confuses most is the way in which Rails does this. The process is handled by [`ActionDispatch::ShowExceptions`](https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/show_exceptions.rb#L44) - which builds a new response out of the one passed to it by the exception generator. Through this process, it calls whichever class is present in [`exceptions_app`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration)...
-![Exceptions handled by the ActiveDispatch::ShowExceptions Middleware][middleware]
+ # show_exceptions.rb
+ def render_exception(request, exception)
+ backtrace_cleaner = request.get_header "action_dispatch.backtrace_cleaner"
+ wrapper = ExceptionWrapper.new(backtrace_cleaner, exception)
+ status = wrapper.status_code
+ request.set_header "action_dispatch.exception", wrapper.exception
+ request.set_header "action_dispatch.original_path", request.path_info
+ request.path_info = "/#{status}"
+ response = @exceptions_app.call(request.env) #-> this is where the HTML is generated
+ response[1]["X-Cascade"] == "pass" ? pass_response(status) : response
+ rescue Exception => failsafe_error
+ $stderr.puts "Error during failsafe response: #{failsafe_error}\n #{failsafe_error.backtrace * "\n "}"
+ FAILSAFE_RESPONSE
+ end
-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):
+In other words, what a user *sees* has very little to do with the fact Rails experienced an error. `ExceptionHandler` doesn't change this behaviour - it simply adds our own controller/views setup to provide the HTML...
-![config.exceptions_app - The key to all Rails exceptions][exceptions_app]
+
+
+
-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.
+To better explain, there are **5️⃣ types of HTTP status code** - [`10x`][10x], [`20x`][20x], [`30x`][30x], [`40x`][40x], & [`50x`][50x].
- **`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:
+Each does its own thing, but what's important is they *ALL* describe "responses" that your web browser will receive for HTTP requests. The only *erroneous* status codes are `4xx` (client error) or `5xx` (server error)...
-![Exceptions handled by the ActiveDispatch::ShowExceptions Middleware][middleware]
+
+
+
-**`ExceptionHandler` is the most EFFECTIVE and EFFICIENT gem to handle exceptions in Rails**.
+The point is that when you're dealing with "errors" online, you're *actually* dealing with erroneous **HTTP STATUS CODES**. The response delivered with these codes is *ALWAYS* going to remain the same; difference lying in how they're built (on the server).
-Once invoked, its `model`, `controller` and `views` work together to serve the best responses to Rails errors ...
+By default, `NGinx` + `Apache` use "static" HTML pages to show the errors - if we're using Rails, we have the ability to create *our own* pages. This is exactly what our gem has been designed to do.
-----------
+**`ExceptionHandler`** provides Rails with the ability to serve ***dynamic*** exception pages, built with **your *own*** layouts/views. By overriding the `exceptions_app` hook, it provides a custom `controller`, `model` and `views` to display custom error pages.
-
-
-
-
- Custom Rails Error Pages - ZERO configuration needed:
-
-
+The system is 100% compatible with Rails 4 & 5 and has already been downloaded **180,000+** times...
-
+
+
+
+
-
- You can install it from the CLI or Gemfile - it will AUTOMATICALLY run in production.
-
- ↓ To run in development, use dev mode ↓
-
+
+
+
🚧 Config 🚧
+
----
+**The ONLY thing you need to configure `ExceptionHandler` is the [`config`](https://github.com/richpeck/exception_handler/blob/master/lib/exception_handler/config.rb)**.
-
- If you want to set it up your way, you can use these features...
-
+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 ([invoked at init](https://github.com/richpeck/exception_handler/blob/master/lib/exception_handler/engine.rb#L44)).
-
-
Config
Dev
Database
Email
Views
Locales
Custom Exceptions
Generators
-
+This can be done in `config/application.rb` or `config/environments/[env].rb` ↴
-----
+```
+# config/application.rb
+
+module YourApp
+ class Application < Rails::Application
+
+ # => This is an example of ALL available config options
+ # => You're able to see exactly how it works here:
+ # => https://github.com/richpeck/exception_handler/blob/master/lib/exception_handler/config.rb
-## Config
+ # => Config hash (no initializer required)
+ config.exception_handler = {
+ dev: nil, # allows you to turn ExceptionHandler "on" in development
+ db: nil, # allocates a "table name" into which exceptions are saved (defaults to nil)
+ email: nil, # sends exception emails to a listed email (string // "you@email.com")
+
+ # On default 5xx error page, social media links included
+ social: {
+ facebook: nil, # Facebook page name
+ twitter: nil, # Twitter handle
+ youtube: nil, # Youtube channel name / ID
+ linkedin: nil, # LinkedIn name
+ fusion: nil # FL Fusion handle
+ },
+
+ # This is an entirely NEW structure for the "layouts" area
+ # You're able to define layouts, notifications etc ↴
+
+ # All keys interpolated as strings, so you can use symbols, strings or integers where necessary
+ exceptions: {
+
+ :all => {
+ layout: "exception", # define layout
+ notification: true, # (false by default)
+ deliver: #something here to control the type of response
+ },
+ :4xx => {
+ layout: nil, # define layout
+ notification: true, # (false by default)
+ deliver: #something here to control the type of response
+ },
+ :5xx => {
+ layout: "exception", # define layout
+ notification: true, # (false by default)
+ deliver: #something here to control the type of response
+ },
+ 500 => {
+ layout: "exception", # define layout
+ notification: true, # (false by default)
+ deliver: #something here to control the type of response
+ },
+
+ # This is the old structure
+ # Still works but will be deprecated in future versions
+
+ 501 => "exception",
+ 502 => "exception",
+ 503 => "exception",
+ 504 => "exception",
+ 505 => "exception",
+ 507 => "exception",
+ 510 => "exception"
+
+ }
+ }
-**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:**
+ end
+end
+```
-[![config][config]](lib/exception_handler/config.rb#L45)
+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.
-If you're using an [`engine`](http://guides.rubyonrails.org/engines.html), you don't need to use an `initializer`:
+--
+
+If using an [`engine`](http://guides.rubyonrails.org/engines.html), **DON'T need an `initializer`**:
# lib/engine.rb
module YourModule
@@ -152,45 +251,58 @@ If you're using an [`engine`](http://guides.rubyonrails.org/engines.html), you d
# => ExceptionHandler
# => Works in and out of an initializer
config.exception_handler = {
- dev: false,
- db: true
+ dev: nil, # => this will not load the gem in development
+ db: true # => this will use the :errors table to store exceptions
}
end
end
-You only need to provide the inputs you want, for example:
+The best thing about using a `config` options block is that you are able to only define the options that you require. This means that if you have particular options you *only* wish to run in `staging`, or have single options for `production` etc...
- # config/application.rb
- config.exception_handler = { dev: true }
+---
- # config/environments/production.rb
- config.exception_handler = { social: { fusion: "flutils" }}
+
+
💻 Dev 💻
+
-----
+As explained, `ExceptionHandler` does not work in `development` mode by default. This is because it overrides the `exceptions_app` middleware hook - which is only invoked in `production` or `staging`...
+
+
+
+
-## Dev Mode
+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" ↴
-**To enable `ExceptionHandler` in dev, enable the [`dev`](lib/exception_handler/config.rb#L38) option:**
+
+
+
-![Dev][dev_mode]
+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...
+
+```
+# config/application.rb
+config.exception_handler = { dev: true }
+```
This disables [`config.consider_all_requests_local`](http://guides.rubyonrails.org/configuring.html#rails-general-configuration), making Rails behave as it would in production:
![Dev][dev_img]
+Obviously, this has other connotations including the likes of making your requests go through your production server etc. For this reason, it's *STRONGLY* recommended you only use the `dev` option to test your layouts etc.
+
----
-## Database
+
+
💾 Database 💾
+
-**We also have `ActiveRecord` integration.**
+If you want to save exceptions to your database, you will need to migrate a new
-If you want to save your exceptions to `db`, you need to enable the `db` config option:
-
- # config/application.rb
- config.exception_handler = {
- db: true
- }
+```
+# config/application.rb
+config.exception_handler = { db: true }
+```
This enables `ActiveRecord::Base` on the [`Exception`](app/models/exception_handler/exception.rb) class, allowing us to save to the database.
@@ -200,7 +312,9 @@ To do this, once you've enabled the option, run `rails db:migrate` from your con
---
-## Email
+
+
✉️ Email ✉️
+
**`ExceptionHandler` also now sends email notifications.**
@@ -217,22 +331,43 @@ If you want to receive emails whenever your application raises an error, you can
---
-## Views
+
+
👓 Views 👓
+
-**From [`0.7.0`](#070), we overhauled the view system:**
+The **views** system in `ExceptionHandler` is modular.
-![View][view_img]
+What *most* people want out of the view is to change the way it ***looks***. This can be done without changing the exception "view" itself...
+
+
+
+
-[Wiew](app/views/exception_handler/exceptions/show.html.erb) is modular - `@exception` populated with [`locales`](#locales).
+To better explain, if [`ExceptionsController`](https://github.com/richpeck/exception_handler/blob/0.8/app/controllers/exception_handler/exceptions_controller.rb) is invoked (by `exceptions_app`), it has **ONE** method ([`show`](https://github.com/richpeck/exception_handler/blob/0.8/app/controllers/exception_handler/exceptions_controller.rb#L42)). This method calls the [`show` view](https://github.com/richpeck/exception_handler/blob/0.8/app/views/exception_handler/exceptions/show.html.erb), which is *entirely* dependent on the locales for content & the layout for the look.
+
+This means that if you wish to change how the view "looks" - you're *either* going to want to change your *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.
+
+-
+
+If you wish to change the "layout" / "look", there are **two** options...
+
+ * Firstly, you can create your own layout. This is done by changing the
+
+ * Secondly,
---
-## Locales
+
+
💬 Locales 💬
+
+
+Locales are used to denote interchangeable text (for different languages).
-**[`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5) introduced [locales](config/locales/exception_handler.yml) ...**
+We've used it for a different purpose - to provide text for our "show" view. The beauty of this is that 1) It's entirely modular & 2) It's extensible (we are able to use as many locales as required)...
[[ locales ]]
+
The `ExceptionHandler` view is populated by [`@exception.description`](app/models/exception_handler/exception.rb#L121), which pulls from the `locales`.
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)
@@ -248,13 +383,13 @@ You get access to `%{message}` and `%{status}`, both inferring from `@exception`
---
-## Layout
-
-**The `layout` has also been improved ↴**
+
+
📋 Layouts 📋
+
![Layout][layout_img]
-We now assign layouts to the **status code** of the response:
+If you want to change the various layouts, you need to use the [`config`](#config) to set them.
![Layout][layouts_img]
@@ -263,7 +398,9 @@ By default, `5xx` errors are shown with our [`exception` layout][layout] - this
---
-## Custom Exceptions
+
+
⛔️ Custom Exceptions ⛔️
+
**Custom Exceptions also supported in [`0.7.5`](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)**
@@ -280,7 +417,9 @@ Because `HTTP` can only process `4xx` / `5xx` errors, if `Rails` raises an excep
---
-## Generators
+
+
💼 Generators 💼
+
**You can generate `ExceptionHandler` into your own application.**
@@ -301,34 +440,79 @@ Each switch defines which folders you want (EG `-v views` will only copy `views`
---
-### Migrations (deprecated)
+
+
✔️ Migrations (deprecated) ✔️
+
+
+**You *DON'T* need to generate a migration any more**.
-**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)**
+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).
-You don't need to generate a migration any more.
+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...
-If you set the `db` option in config, run `rails db:migrate` and the migration will be run.
+> If you set the `db` option in config, run `rails db:migrate` and the migration will be run.
To rollback, use the following:
rails db:migrate:down VERSION=000000
-> 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.
+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.
----
+
+
+
![](https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png)
+
☎️ Support ☎️
+
![](https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png)
+
-## Support
+🚨 Obviously, if you've taken the time to use the gem, it makes sense to support it 🚨!
-[Issues](https://github.com/richpeck/exception_handler/issues)
+The fastest way to get a **direct response** is via [email](mailto:rpeck@frontlineutilities.co.uk).
----
+You're also welcome to access our [**Issues**](https://github.com/richpeck/exception_handler/issues) page to contact us directly. You could also use [**StackOverflow**](https://stackoverflow.com/questions/tagged/ruby-on-rails+exceptionhandler)...
+
+ - ⚠️ [**Issues**](https://github.com/richpeck/exception_handler/issues) ⚠️
+ - 🚩 [**StackOverflow**](https://stackoverflow.com/questions/tagged/ruby-on-rails+exceptionhandler) 🚩
+ - ✉️ [**Email**](mailto:rpeck@frontlineutilities.co.uk) ✉️
+ - ✏️ [**Medium**](https://medium.com/ruby-on-rails-web-application-development/custom-400-500-error-pages-in-ruby-on-rails-exception-handler-3a04975e4677) ✏️
+ - 🎥 [**YouTube**](https://www.youtube.com/channel/UC247lm76ECX1aSvVuhXxe6g) 🎥 ↴
+
+
+
+
+
+
+
+
![](https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png)
+
⭐ Changelog ⭐
+
![](https://cdn-images-1.medium.com/max/800/1*CKyKxRXLovcrUOB-s8_jCw.png)
+
-## Changelog
+The most important thing to appreciate is...
-### [0.7.5](https://github.com/richpeck/exception_handler/releases/tag/0.7.5)
+➡️ ExceptionHandler
is designed to provide custom error pages for Ruby on Rails. ⬅️
+
+If you're looking at adding extra functionality (such as a debugger), you'll probably be better looking at the likes of better_errors
or gaffe
. Whilst we'll certainly look at adding - or integrating - other features (if they're requested), our core intention has always been to provide an exception handling stack that was both simple and customizable.
+
+--
+
+What we've built so far...
+
+### 👻 [1.0.0.0](https://github.com/richpeck/exception_handler/releases/tag/v1.0.0.0)
+ - [ ] TBA
+
+### 🏹 [0.8.0.0](https://github.com/richpeck/exception_handler/releases/tag/v0.8.0.0)
+ - [x] [README](https://github.com/richpeck/exception_handler/issues/52) (focus on utility)
+ - [x] Introduction of `4xx`,`5xx`,`:all` for layouts config
+ - [x] Changed `layouts` to `exceptions` in config
+ - [x] Email improvement
+ - [x] Streamlined migration
+ - [x] Updated model
+
+### 👽 [0.7.7.0](https://github.com/richpeck/exception_handler/releases/tag/v0.7.7.0)
- [x] [HTTP status layouts](#layouts)
-### [0.7.0](https://github.com/richpeck/exception_handler/releases/tag/0.7.0)
+### ⚡ 0.7.0.0
- [x] Wildcard mime types
- [x] [Custom exceptions](#custom_exceptions)
- [x] Test suite integration
@@ -338,7 +522,7 @@ To rollback, use the following:
- [x] New layout
- [x] Readme / wiki overhaul
-### [0.6.5](https://github.com/richpeck/exception_handler/releases/tag/0.6.5)
+### Ⓜ️ 0.6.5.0
- [x] Streamlined interface
- [x] ActiveRecord / Middleware overhaul
- [x] Supports Sprockets 4+ ([`manifest.js`](http://eileencodes.com/posts/the-sprockets-4-manifest/))
@@ -346,7 +530,7 @@ To rollback, use the following:
- [x] Asset overhaul & improvement
- [x] Removed dependencies
-### [0.5.0](https://github.com/richpeck/exception_handler/releases/tag/0.5.0)
+### ✔️ 0.5.0.0
- [x] Locales
- [x] Email notifications
- [x] Full test suite
@@ -357,20 +541,23 @@ To rollback, use the following:
- [x] Rails asset management improvement
- [x] Reduced gem file size
-### [0.4.7](https://github.com/richpeck/exception_handler/releases/tag/0.4.6)
+### ⭕ 0.4.7.0
- [x] New config system
- [x] Fixed controller layout issues
- [x] Streamlined middleware
- [x] New layout & interface
-----
+
+
+
+
[![404 + 500 Errors][banner]][rubygems]
- ExceptionHandler is now the leading custom error pages gem for Rails.
+ ExceptionHandler
is now the • LEADING • custom error pages gem for Rails 4 & 5...
- No other gem is as simple or effective at providing beautiful exception pages in production.
+ No other gem is as simple or effective at providing branded exception pages in production...
@@ -383,12 +570,16 @@ To rollback, use the following:
- Download Here
+ ➡️ Download & Info ⬅️
+
+
+
+
+
-----------
+:copyright:
-:copyright:
@@ -436,5 +627,11 @@ To rollback, use the following:
[pull]: http://github.com/richpeck/exception_handler/pulls
[issues]: http://github.com/richpeck/exception_handler/issues
+[10x]: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#1xx_Informational_responses
+[20x]: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success
+[30x]: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection
+[40x]: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_errors
+[50x]: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_errors
+
diff --git a/app/assets/stylesheets/exception_handler.css.erb b/app/assets/stylesheets/exception_handler.css.erb
index afcb6422..77051c4e 100644
--- a/app/assets/stylesheets/exception_handler.css.erb
+++ b/app/assets/stylesheets/exception_handler.css.erb
@@ -15,4 +15,9 @@
*/
/* ---------------------------------------------------- */
/* ---------------------------------------------------- */
+/*
+ *= link_tree ../images
+*/
+/* ---------------------------------------------------- */
+/* ---------------------------------------------------- */
/* ---------------------------------------------------- */
diff --git a/app/assets/stylesheets/styles/_base.css.erb b/app/assets/stylesheets/styles/_base.css.erb
index 4d603b5a..c7e85bb9 100644
--- a/app/assets/stylesheets/styles/_base.css.erb
+++ b/app/assets/stylesheets/styles/_base.css.erb
@@ -4,19 +4,12 @@
/* ---------------------------------------------------- */
/* ---------------------------------------------------- */
-/*
- *= link_tree ../../images
-*/
-
-/* ---------------------------------------------------- */
-/* ---------------------------------------------------- */
-
* { margin: 0; }
html, body { height: 100%; }
html {
height: 100%;
color: #fff;
- background: #010008 url(<%= asset_url("exception_handler/bg.jpg") %>) top left no-repeat;
+ background: #121212;
background-size: 100% 100%;
box-sizing: border-box;
}
diff --git a/app/assets/stylesheets/styles/_exception.css.erb b/app/assets/stylesheets/styles/_exception.css.erb
index 2027b1eb..4d9ef5fe 100644
--- a/app/assets/stylesheets/styles/_exception.css.erb
+++ b/app/assets/stylesheets/styles/_exception.css.erb
@@ -53,7 +53,8 @@
border-color: rgba(255,255,255,0.09);
border-style: solid
}
-.exception:hover { cursor: pointer; }
+.exception:hover { cursor: pointer; }
+.exception:hover:after { text-decoration: underline; }
.exception span:before {
display: block;
diff --git a/app/controllers/exception_handler/exceptions_controller.rb b/app/controllers/exception_handler/exceptions_controller.rb
index 7c078b34..4f2f2389 100644
--- a/app/controllers/exception_handler/exceptions_controller.rb
+++ b/app/controllers/exception_handler/exceptions_controller.rb
@@ -36,9 +36,11 @@ class ExceptionsController < ApplicationController
layout :layout
####################
- # Action #
+ # Actions #
####################
+ # => General Show Functionality
+ # => Introduced new "action" config option in 0.8.0.0
def show
respond_with @exception, status: @exception.status
end
@@ -48,8 +50,13 @@ def show
private
- def layout
- ExceptionHandler.config.layouts[@exception.status]
+ # => Pulls from Exception class
+ # => Spanner in the works is nil
+ # => .present? validates against empty strings (IE a string is present)
+ # => .nil? validates to see if the returned data is "nil"
+ # => nil required to facilitate inheritance of the layout w/ ApplicationController
+ def layout option = ExceptionHandler.config.options(@exception.status, :layout)
+ (option.present? || option.nil?) ? option : 'exception'
end
##################################
diff --git a/app/models/exception_handler/exception.rb b/app/models/exception_handler/exception.rb
index a144c859..f9e3803e 100644
--- a/app/models/exception_handler/exception.rb
+++ b/app/models/exception_handler/exception.rb
@@ -10,20 +10,13 @@ module ExceptionHandler
# => Attributes
# => Determine schema etc
ATTRS = %i(class_name status message trace target referrer params user_agent)
-
- # => Exceptions to be rescued by ExceptionHandler
- EXCEPTIONS_TO_BE_RESCUED = [ActionController::RoutingError, AbstractController::ActionNotFound].tap do |list|
- list << ActiveRecord::RecordNotFound if defined?(ActiveRecord)
- list << Mongoid::Errors::DocumentNotFound if defined?(Mongoid)
- end
############################################################
############################################################
# => Class (inheritance dependent on whether db option is available)
- self::Exception = Class.new(
- (ExceptionHandler.config.try(:db) && defined?(ActiveRecord)) ? ActiveRecord::Base : Object
- ) do
+ self::Exception =
+ Class.new( (ExceptionHandler.config.try(:db) && defined?(ActiveRecord)) ? ActiveRecord::Base : Object ) do
# => Include individual elements
# => Only required if no db present (no ActiveRecord)
@@ -97,15 +90,14 @@ def self.table_name
# => Email
# => after_initialize invoked after .new method called
# => Should have been after_create but user may not save
- after_initialize Proc.new { |e| ExceptionHandler::ExceptionMailer.new_exception(e).deliver } if ExceptionHandler.config.try(:email).try(:is_a?, String)
+ after_initialize -> (e) { ExceptionHandler::ExceptionMailer.new_exception(e).deliver }, if: :email? # => see bottom of file
# => Attributes
attr_accessor :request, :klass, :exception, :description
attr_accessor *ATTRS unless ExceptionHandler.config.try(:db)
# => Validations
- validates :klass, exclusion: { in: EXCEPTIONS_TO_BE_RESCUED, message: "%{value}" }, if: -> { referer.blank? } # => might need full Proc syntax
- validates :user_agent, format: { without: Regexp.new( BOTS.join("|"), Regexp::IGNORECASE ) }
+ validates :user_agent, format: { without: Regexp.new( BOTS.join("|"), Regexp::IGNORECASE ) }
##################################
##################################
@@ -114,21 +106,22 @@ def self.table_name
# Virtual
####################################
+ # => Exception (virtual)
+ # => Basis on which all the class is built
+ def exception
+ request.env['action_dispatch.exception']
+ end
+
# => Klass
# => Used for validation (needs to be cleaned up in 0.7.0)
def klass
exception.class
end
- # => Exception (virtual)
- def exception
- request.env['action_dispatch.exception']
- end
-
# => Description
def description
I18n.with_options scope: [:exception_handler], message: message, status: status do |i18n|
- i18n.t response, default: Rack::Utils::HTTP_STATUS_CODES[status] || status
+ i18n.t response, default: Rack::Utils::HTTP_STATUS_CODES[status]
end
end
@@ -143,7 +136,7 @@ def class_name
# => Message
def message
- exception.message
+ exception ? exception.message : Rack::Utils::HTTP_STATUS_CODES[status]
end
# => Trace
@@ -181,7 +174,7 @@ def user_agent
# => Status code (404, 500 etc)
def status
- ActionDispatch::ExceptionWrapper.new(request.env, exception).status_code
+ exception ? ActionDispatch::ExceptionWrapper.new(request.env, exception).try(:status_code) : request.env["PATH_INFO"][1..-1].to_i
end
# => Server Response ("Not Found" etc)
@@ -192,6 +185,14 @@ def response
##################################
##################################
+ private
+
+ # => Email
+ # => should be on the same line as after_initialize but too long
+ def email?
+ ExceptionHandler.config.try(:email).try(:is_a?, String) && ExceptionHandler.config.options(status, :notification) != false
+ end
+
end
end
diff --git a/app/views/exception_handler/exceptions/show.html.erb b/app/views/exception_handler/exceptions/show.html.erb
index 0d56a351..5e036cd1 100644
--- a/app/views/exception_handler/exceptions/show.html.erb
+++ b/app/views/exception_handler/exceptions/show.html.erb
@@ -1,3 +1,3 @@
-<%= content_tag :div, class: "exception", data: { status: @exception.status, response: @exception.response.to_s.humanize, rails: Rails.version }, onclick: ("location.href=\"#{root_url}\";" if @exception.status == "500" && Rails.application.routes.recognize_path("/")), title: ("Return Home" if @exception.status == "500" && Rails.application.routes.recognize_path("/")) do %>
+<%= content_tag :div, class: "exception", data: { status: @exception.status, response: @exception.response.to_s.humanize, rails: Rails.version }, onclick: ("location.href=\"#{root_url}\";" if @exception.status.to_s.first == "5" && Rails.application.routes.recognize_path("/")) do %>
<%= content_tag :span, @exception.description.html_safe %>
<% end %>
diff --git a/app/views/layouts/exception.html.erb b/app/views/layouts/exception.html.erb
index cf772ebc..ff249554 100644
--- a/app/views/layouts/exception.html.erb
+++ b/app/views/layouts/exception.html.erb
@@ -9,6 +9,10 @@
<%= stylesheet_link_tag :exception_handler %>
<%= favicon_link_tag "exception_handler/favicon.ico" %>
+ <% if x = ExceptionHandler.config.options(@exception.status) %>
+
+ <% end %>
+
<%= csrf_meta_tags %>
@@ -24,4 +28,5 @@
<% end %>
<% end %>
<% end %>
+