Coder Social home page Coder Social logo

exception_handler's Introduction

Exception Handler

Gem Version Code Climate Dependency Status Coverage Status Build Status

ExceptionHandler Rails Gem (adapted from this tutorial & this tutorial)

Works with the config.exceptions_app hook in Rails' middleware stack:

config.exceptions_app sets the exceptions application invoked by the ShowExceptionmiddleware
when an exception happens. Defaults to ActionDispatch::PublicExceptions.new(Rails.public_path).

####Custom Error Pages

ExceptionHandler deploys custom error pages. These allow you to serve your own design error pages in production; showing both the error, and the problem. This is a big step forward from the standard Rails error reporting facility

There are two types of error page:

- 404 errors
- 500 errors (+ other)

The custom 404 error uses your own layout. The 500 & other errors are server issues, and so we have included an errors layout (/views/layouts/errors.html.erb).

The errors layout in important. If you try and load your "standard" layout with an internal server error, all your "supporting" functionality is called too. Problem? You're likely going to cause even more errors.

Custom error pages are included by default. You can change them by using the rails generate exception_handler:assets --views:

500 Errors 404 Errors
500 Server Error Pages 404 Server Error Pages
Uses errors layout Uses standard layout

####Saving Errors To DB

Adapted & refactored from this tutorial

Sometimes, you want to save your errors to your database (admin areas, multi-tenant apps, etc). We've included some middleware which captures the exceptions & saves them to the db:

- Model (class) Name
- Error Message
- Stack trace
- Target URL
- Referrer URL
- Params
- User Agent (Browser Details)

This db allows you to track, read & repair errors in your application on the fly. We deploy this in our admin areas, to help us appreciate any issues on our client apps.

Errors Table

This functionality is disabled by default

To enable, you need to do the following:

- rails generate exception_handler:install #-> will install config initializer
- rails generate exception_handler:migration #-> will create migration (for `errors` table)
- rake db:migrate #-> creates `errors` table

- config/initializers/exception_handler.rb
- ExceptionHandler.setup do |config|
-    config.db = true
- end

Installation

###Step1

You need to reference the exception_handler gem. Once you have downloaded the gem, you'll be able to deploy it in your application.

Add this line to your application's Gemfile:

gem 'exception_handler'

And then execute:

$ bundle

Or install it yourself as:

$ gem install exception_handler

gem install

--

###Step2

Run:

rails generate exception_handler:install

Installation

This will create config/initializers/exception_handler.rb. Whilst not vital, it will give you access to the configuration options which can change the gem's behavior:

Config File

--

###Database

If you want to set up the database, you will need to use the migration installer:

$ rails generate exception_handler:migration

This creates:

$ rake db:migrate

This will migrate the datatable for you. Now you need to change config.db = true

DB Config


###Configuration

Exception handler comes with 3 installers

You only need to use rails generate exception_handler:install. The others allow you to include files on your system, or create the errors table.

# General
$ rails generate exception_handler:install #-> installs "config" file (initializer)

Install

# Migration
$ rails generate exception_handler:migration #-> generates migration for "errors" table

Migration Install

# Files
$ rails generate exception_handler:views #-> controller, models, views & assets
$ rails generate exception_handler:views -v views controllers models assets #-> remove as appropriate to install individual assets

Views Install


Usage

###Development Environment

config.exceptions_app is only used in Rails' production environment. Therefore, if you wish to test the gem in dev, you'll need to make your app process requests as production for now. This is a temporary step, and will be resolved in a new version:

#config/environments/development.rb
config.consider_all_requests_local = false # true

Development Testing

You should change this setting if you wish to test your styling in development mode. Please note it should be temporary

--

###Production Environment

No action required

###Demo

404 Error 500 Error
404 Error Page 500 Error Page
Link Link

Support

If you need help, you may consider:

  1. Watching this video tutorial:

    ExceptionHandler Update

  2. Read our tutorial

  3. Ask on StackOverflow

  4. Go on the gem support page


Contributing

  1. Fork it ( https://github.com/richpeck/exception_handler/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.