logankoester / errship

Errship is a Rails 3.1 engine for rendering error pages inside your layout. It supports i18n, custom exceptions, and Airbrake error tracking.
http://blog.logankoester.com/errship.html
MIT License
26 stars 5 forks source link

= => errship

The static error pages Rails comes with are nice for getting started - you can't break them, no matter what. But without your layout and navigation wrapped around them, they create a frustrating trap for your users.

The obvious solution is to render your layout into the static file, but what happens when you make a change?

Worse, what if you run a network of many Rails applications? Should they share one error page style? Should they all have their own?

You could hire your nephew to keep them all up to date... or you can use Errship.

Errship is a Rails 3.1 engine for rendering error pages inside your layout. It supports i18n, custom exceptions, and Airbrake (Hoptoad) error tracking.

You can also use the flashback method to set an error message and redirect :back safely - if a RedirectBackError is raised, the user is dropped off at the nearest error page and given the flash message anyway.

== Installation

Add this to your Gemfile gem 'errship', '~> 2.2.0'

Add this to your ApplicationController class ApplicationController < ActionController::Base include Errship::Rescuers include Errship::ActiveRecord::Rescuers # or replace 'ActiveRecord' with MongoMapper, or Mongoid

Errship is ready to go! To test it out in development, you'll need to set

config.consider_all_requests_local = false

in your config/environments/development.rb file. Just don't forget to change it back when you want useful debugging output again instead!

Alternatively, simply point your browser to /error or /not_found to get a taste.

== Configuration

Errship renders all error pages with a HTTP status of 200 by default. This is done to ensure that the error page is rendered if the web server is configured to intercept errors (e.g. proxy_intercept_errors for nginx). If you want to have the correct status codes for your errors, add the following to an initializer:

Errship.status_code_success = false

== I18n

If you want to edit the text that is rendered, add the following to your config/locales/*.yml

en:
  errship:
    '404':
      title: 'This page does not exist.'
      description: 'It could have moved, or someone (maybe you!) mistyped the URL.'
    '500':
      title: 'An error has occurred.'
      description: 'This has been reported to our development team. Thank you!'

...and so forth, for any error code you like.

== Custom Rescuers

If you want errship to rescue errors from your own custom exception class, you need to add a custom rescuer in your ApplicationController, like so:

# Render the 404 page
rescue_from MyException::SomethingMissing, :with => :render_404_error

# Render the 500 page
rescue_from MyException::SomethingWentWrong, :with => :render_error

To customize the error for a particular controller or exception class, add a rescuer like this one:

rescue_from ActiveRecord::RecordNotFound, :with => ->(e){ render_404_error e, 'monkeys' }

and then add your text for that scope to config/locales/*.yml

en:
  errship:
    '404':
      title: 'This page does not exist.'
      description: 'It could have moved, or someone (maybe you!) mistyped the URL.'
      monkeys:
        title: 'They must have escaped'
        description: 'This is now a monkey free zone.'

The following methods are provided:

If Airbrake is installed, every rescuer will report the exception, except for 404.

== Changelog

2.2.0

2.1.3

2.1.2

2.1.1

2.1.0

2.0.1

2.0.0

1.1.0

1.0.0

== Contributing to errship

== Copyright

Copyright (c) 2011-2014 Logan Koester. See LICENSE.txt for further details.