Git Product home page Git Product logo

exception_handler's Introduction

Exception Handler

ExceptionHandler is presently the MOST POPULAR exceptions gem for CUSTOM Rails error pages.

With 290,000+ downloads, it is the *only* gem to provide custom 400/500 exception pages for Rails 5 & 6

Current 0.8.0.0 (August 2018)

Coverage Status

๐Ÿ“ Introduction - โš ๏ธ Installation - ๐Ÿ”ง Configuration - โ˜Ž๏ธ Support - โญ Changelog

๐Ÿ“ Introduction


ExceptionHandler replaces Rails' default error pages with dynamic views.

It does this by injecting config.exceptions_app 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:

Rails uses ActionDispatch::ShowExceptions (above) to generate error responses.

Because web browsers (Rails is a web framework) can only interpret HTTP responses, Ruby/Rails exceptions have to be translated into something a browser can read. This is done by calling the above middleware.

--

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 ExceptionHandler is designed to override.

โš ๏ธ Installation


๐Ÿ’Ž RubyGems (Code) | ๐Ÿ’ป Medium (Tutorial)

# Gemfile
gem 'exception_handler', '~> 0.8.0.0'

Because ExceptionHandler is built around a Rails engine, there is nothing to be done to get it working in production. Installing the Gem should translate your production 4xx/5xx error pages into dynamic views.

Environments other than production (development/staging) required the dev variable to be true.

๐Ÿ”ง Configuration


๐Ÿ“ Configย ย ย ย ๐Ÿ’ป Devย ย ย ย ๐Ÿ’พ Databaseย ย ย ย โœ‰๏ธ Emailย ย ย ย ๐Ÿ‘“ Viewsย ย ย ย ๐Ÿ’ฌ Localesย ย ย ย ๐Ÿ“‹ Layoutsย ย ย ย โ›”๏ธ Custom Exceptions


The ONLY thing you need to manage ExceptionHandler is its config settings.

Whilst the gem works out of the box (without any configuration), if you want to manage the layouts, email, dev or the database, you'll need to set the appropriate values in the config hash.

This is 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 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 // "[email protected]")

      # Custom Exceptions
      custom_exceptions: {
        #'ActionController::RoutingError' => :not_found # => example
      },

      # 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"

      }
    }
  end
end

For a full retinue of the available options, you'll be best looking at the config file itself.

--

If using an engine, you DON'T need an initializer:

# lib/engine.rb
module YourModule
  class Engine < Rails::Engine

    # => ExceptionHandler
    # => Works in and out of an initializer
    config.exception_handler = {
      dev: nil, # => this will not load the gem in development
      db:  true # => this will use the :errors table to store exceptions
    }
  end
end

The best thing about using a config options block is that you are able to only define the options that you require.

If you have particular options you only wish to run in staging, or have single options for production etc, this setup gives you the ability to manage it properly...


๐Ÿ’ป Dev

As explained, ExceptionHandler does not work in development by default.

This is because it overrides the exceptions_app middleware hook - which is only invoked in production or staging.

To get it working in development, you need to override the config.consider_all_requests_local setting (a standard component of Rails) - setting it to "false" โ†ด

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, making Rails behave as it would in production.

Whilst simple, it's not recommended for extended use. Very good for testing new ideas etc.


๐Ÿ’พ DB

To save exceptions to your database, you're able to set the db option.

Because we use a controller to manage the underlying way the system works, we're able to invoke the likes of a model with other functionality.

Ths is done automatically with the latest version of ExceptionHandler.

To do this, once you've populated the option with either true or a string, run rails db:migrate from your console.

Our new migration system will automatically run the migration.

# config/application.rb
config.exception_handler = { db: true }

This enables ActiveRecord::Base on the Exception class, allowing us to save to the database.

In order for this to work, your db needs the correct table.


โœ‰๏ธ Email

ExceptionHandler also sends email notifications.

If you want to receive emails whenever your application raises an error, you can do so by adding your email to the config:

# config/application.rb
config.exception_handler = {
  email: "[email protected]"
}

Please Note this requires ActionMailer. If you don't have any outbound SMTP server, SendGrid is free.

From version 0.8.0.0, you're able to define whether email notifications are sent on a per-error basis:

# config/application.rb
config.exception_handlder = {

  # This has to be present for any "notification" declarations to work
  # Defaults to 'false'
  email: "[email protected]",

  # Each status code in the new "exceptions" block allows us to define whether email notifications are sent
  exceptions: {
    :all => { notification: true },
    :50x => { notification: false },
    500 =>  { notification: false }
  }
}

๐Ÿ‘“ Views

What most people want out of the view is to change the way it looks. This can be done without changing the "view" itself.

To better explain, if ExceptionsController is invoked (by exceptions_app), it has ONE method (show).

This method calls the show view, 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 layout or the 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.

--

We've also included a number of routes which shows in dev mode (allowing you to test):


๐Ÿ’ฌ Locales

Locales are used to create interchangeable text (translations/internationalization).

--

In ExceptionHandler, it provides the wording for each type of error code.

By default, the English name of the error is used ("404" will appear as "Not Found") - if you want to create custom messages, you're able to do so by referencing the error's "status_code" within your locales file:

# config/locales/en.yml
en:
  exception_handler:
    not_found:              "Your message here" # -> 404 page
    unauthorized:           "You need to login to continue"
    internal_server_error:  "This is a test to show the %{status} of the error"

You get access to %{message} and %{status}, both inferring from an @exception object we invoke in the controller...

  • %{message} is the error's actual message ("XYZ file could not be shown")
  • %{status} is the error's status code ("Internal Server Error")

--

By default, only internal_server_error is customized by the gem:

# config/locales/en.yml
en:
  exception_handler:
    internal_server_error: "<strong>%{status} Error</strong> %{message}"

๐Ÿ“‹ Layouts

The most attractive feature of ExceptionHandler (for most) is its ability to manage layouts for HTTP status.

--

The reason for this is due to the way in which Rails works โ†’ the "layout" is a "wrapper" for the returned HTML (the "styling" of a page). If you have no layout, it will render the "view" HTML and nothing else.

This means if you want to change the "look" of a Rails action, you simply have to be able to change the layout. You should not change the view at all.

To this end, ExceptionHandler has been designed around providing a SINGLE VIEW for exceptions. This view does not need to change (although you're welcome to use a generator to do so) - the key is the layout that's assigned...

  • 4xx errors are given a nil layout (by default) (inherits from ApplicationController in your main app)
  • 5xx errors are assigned our own exception layout:
# config/application.rb
config.exception_handler = {

  # The new syntax allows us to assign different values to each HTTP status code
  # At the moment, only 'layout' & 'notification' are supported
  # We plan to include several more in the future...

  exceptions: {
    all: { layout: nil } # -> this will inherit from ApplicationController's layout
  }
}

The layout system has changed between 0.7.7.0 and 0.8.0.0.

Building on the former's adoption of HTTP status-centric layouts, it is now the case that we have the all, 5xx and 4xx options - allowing us to manage the layouts for blocks of HTTP errors respectively:

# config/application.rb
config.exception_handler = {

  # Old (still works)
  # No "all" / "4xx"/"5xx" options
  layouts: {
    500 => 'exception',
    501 => 'exception'
  },

  # New
  exceptions: {
    :all => { layout: 'exception' },
    :4xx => { layout: 'exception' },
    :5xx => { layout: 'exception' }, # -> this overrides the :all declaration
    500  => { layout: nil } # -> this overrides the 5xx declaration
  }
}

We've bundled the exception layout for 5xx errors because since these denote internal server errors, it's best to isolate the view system as much as possible. Whilst you're at liberty to change it, we've found it sufficient for most use-cases.


โ›”๏ธ Custom Exceptions

As mentioned, Rails' primary role is to convert Ruby exceptions into HTTP errors.

Part of this process involves mapping Ruby/Rails exceptions to the equivalent HTTP status code.

This is done with config.action_dispatch.rescue_responses.

Whilst this works well, it may be the case that you want to map your own classes to an HTTP status code (default is Internal Server Error).

If you wanted to keep this functionality inside ExceptionHandler, you're able to do it as follows:

# config/application.rb
config.exception_handler = {
  custom_exceptions: {
    'CustomClass::Exception' => :not_found
  }
}

Alternatively, you're able to still do it with the default Rails behaviour:

# config/application.rb
config.action_dispatch.rescue_responses = { 'CustomClass::Exception' => :not_found }

๐Ÿ’ผ Generators

If you want to edit the controller, views, model or assets, you're able to invoke them in your own application.

This is done - as with other gems - with a single generator which takes a series of arguments:

rails g exception_handler:views
rails g exception_handler:views -v views
rails g exception_handler:views -v controllers
rails g exception_handler:views -v models
rails g exception_handler:views -v assets
rails g exception_handler:views -v views controllers models assets

If you don't include any switches, this will copy all ExceptionHandler's folders put into your app.

Each switch defines which folders you want (EG -v views will only copy views dir).


โœ”๏ธ Migrations

You DON'T need to generate a migration anymore.

From 0.7.5, the migration generator has been removed in favour of our own migration system.

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.

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.

โ˜Ž๏ธ Support


You're welcome to contact me directly at [email protected].

Alternatively, you may wish to post on our GitHub Issues, or StackOverflow.

--

Medium

โญ Changelog


1.0.0.0

  • TBA

0.8.0.0

  • README (focus on utility)
  • Introduction of 4xx,5xx,:all for layouts config
  • Changed layouts to exceptions in config
  • Email improvement
  • Streamlined migration
  • Updated model

0.7.7.0

0.7.0.0

0.6.5.0

  • Streamlined interface
  • ActiveRecord / Middleware overhaul
  • Supports Sprockets 4+ (manifest.js)
  • Email integration
  • Asset overhaul & improvement
  • Removed dependencies

0.5.0.0

  • Locales
  • Email notifications
  • Full test suite
  • Rails 4.2 & Rails 5.0 native (request.env fix)
  • Controller fixed
  • DB fixed
  • Legacy initializer support (more)
  • Rails asset management improvement
  • Reduced gem file size

0.4.7.0

  • New config system
  • Fixed controller layout issues
  • Streamlined middleware
  • New layout & interface

404 + 500 Errors

ExceptionHandler provides custom error pages gem for Rails 5+
No other gem is as simple or effective at providing branded exception pages in production

Coverage Status

โžก๏ธ Download & Info โฌ…๏ธ

ยฉ๏ธ

exception_handler's People

Contributors

acrogenesis avatar brunoocasali avatar frankzhao avatar kacperjurak avatar mabako avatar max-si-m avatar nktkaa avatar richpeck avatar startouf avatar tonkonozhenko avatar toymachiner62 avatar yrashk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

exception_handler's Issues

Trouble Installing on Heroku

I included gem 'exception_handler', '~> 0.6.5' in my Gemfile and ran a bundle install. I do not see any of the assets (exception controller, defaults views, etc.) in my project and exceptions are not being handled by Exception Handler. I am using Rails 5 and developing in Heroku. What am I doing wrong?

Is there anyway to stop handling 40* errors altogether?

I'm working on an existing rails app, and in many cases we return json with custom error messages for 404s. I added this gem to handle 500s, but since it catches 404s as well, we're running into some unintended side effects. I tried returning json in the case of 404, but it doesn't have the original text and I'm concerned api users might be dependent on the error text.

There are too many of these situations to handle it in the ExceptionHandler controller.

Any suggestions?

Both errors rendering within an application view

Processing by ExceptionHandler::ExceptionController#show as HTML
Rendered exception_handler/exception/show.html.haml within layouts/application (3.7ms)

How to resolve this issue?
If you need my setup details, please ask (It was done gem docs)

undefined local variable or method `info' for ExceptionHandler::Parser::Data:Class

Hi!

Just updated from 0.4.7 to 0.5.1 but there seems to be a bug in lib/exception_handler/parser/data.rb.
If my application throws an error, the exceptionhandler fails.

It tries to access the private "info" instance method from the class method "create". I see what you did in the change between 0.4.7 and 0.5.1, in the old version the initalize and save methods are instance methods that can access the info instance method. This code is moved to the new create class method but now "info" is unreachable.

Undefined method `save'

Running into the following error with db: true

Error during failsafe response: undefined method `save' for #<ExceptionHandler::Exception:0x007fb5300baa30>
  .../exceptions_controller.rb:21:in `block in <class:ExceptionsController>'

Line 21:

before_action { @exception.save if @exception.valid? && ExceptionHandler.config.try(:db) }

Cannot use gem with database

Hi!

I have done this steps:

gem 'exception_handler', '~> 0.4'

$ bundle
$ rails g exception_handler:install
$ rails generate exception_handler:migration
$ rake db:migrate

Error 1

NoMethodError: undefined method `new' for ExceptionHandler:Module
active_record/migration.rb:774:in `load_migration'

Solution 1

Rename file 20151110090613_exception_handler.rb to 20151110090613_create_errors.rb or rename class name from CreateErrors to ExceptionHandler.

Error 2

If I rename the migration from 20151110090613_exception_handler.rb to 20151110090613_create_errors.rb the Error 1 disappears but then I get another error.

== 20151110090613 CreateErrors: migrating =====================================
-- create_table(:errors)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedTable: ERROR:  relation "usables" does not exist

Solution 2

Change migration usable reference to

t.references :usable, polymorphic: true

Using with active admin?

I've been trying to add an activeadmin resource for the model you're using, but no luck. Has anybody done this?

NameError: uninitialized constant CreateErrors

Hello everyone,
i have an error when running rake db:migrate after generating migration file.

My migration file looks like this

create_table :false do |t|
  t.references  :usable, polymorphic: true
  t.text        :class_name
  t.text        :message
  t.text        :trace
  t.text        :target_url
  t.text        :referer_url
  t.text        :params
  t.text        :user_agent
  t.timestamps
end

This is the error
NameError: uninitialized constant CreateErrors

Thanks in advance for your help

Is it working with rails 3?

After bundle update cannot get work my rails 3 application now ((

undefined method `setup' for ExceptionHandler:Module (NoMethodError)

Only Rails FAILSAFE message is being shown

I'm guessing I'm doing something wrong, but the only error message that shows up is:

500 Internal Server Error
If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong.

Running Rails 4.1 and Ruby 2.3.1.

The only thing I did to "install" exception_handler is to put it in my Gemfile:

gem 'exception_handler', '~> 0.5.0' #-> Gemfile

Gem size is 67M compressed!

The size of the compressed .gem file is about 67M. That is unusually large for a gem, and even for a Rails engine gem.

It may be a good idea to get rid of the Photoshop files:

  • readme/source/screen.psd - 49M
  • readme/source/subtitle.psd - 59M
  • readme/source/title.psd - 7.2M

I'll add a PR. Feel free to use it... or not. #25

How do you see the Exception View in dev?

I haven't figured out how to see the Exception View in dev. When I'm in production (on Heroku) and an error occurs, the error pages appear just fine, but I would like to customize this page, which is much harder if I can't see it in my dev environment.

Specify app directory where exception_handler picks up custom views

First of all, thank you for this gem + the detailed article on using middle-ware level exception handling. Your work is very much appreciated.

Our rails project is heavily engine/component based so there is no root app directory (more like /engines/X/app/, /engines/Y/app etc..

We had trouble to get it working by including it within the engines, so it has been included it in the root folders Gemfile.

One issue with using root was that ExceptionHandler assumes a ::ApplicationController exists (engines do namespace X::ApplicationController) but this can be worked around by re-defining ::ApplicationController.

Second issue is that if views are missing in root/app/views/ it automatically picks up the gem's default views. So generating custom views/layouts in the root app dir works but i'd rather place them into the engines app dir. As a side note: Rails picks up overrides automatically in the order of mounting if placed in the engines app dir but this happens only for mounted engines.

Q: Is there a config option to override the asset/views path so it picks up my views folder first instead of root views folder or default views from the gem. Alternatively is there a way or example of how to run it from an engine which has been mounted ?

(Worst case we'd need to create an app folder in root, which would be containing only exception_handler code).

Actions return wrong HTTP status code

On Rails 4.1, when I use the gem, the rendered 404 page has a HTTP status code of 200. The original status code should be preserved.

I think that the gem is trying to do the correct thing - in the controller, the line is:

respond_with status: @status

But this doesn't work in Rails 4.1 and earlier, the correct way would be:

respond_with nil, status: @status

You need to pass the resources first.

However, I haven't submitted a pull request because with Rails 4.2 out, you probably need to move away from respond_with - it's been deprecated and move out into the responders gem. Or use the responders gem. Not sure which is best, I haven't dug into 4.2 yet.

Migration fails with: NoMethodError: undefined method `[]' for ActiveRecord::Migration...

After enabling the db option in app...config, then running migrations, I was receiving this error:

NoMethodError: undefined method `[]' for #<ActiveRecord::Migration: ...

Not sure, but I think your migration relies on rails5, (I'm on 4.x). I worked around it by disabling db in config, which you have to in order to generate the migration by hand (would get a migration pending exception otherwise), then determining what the proper migration would be by looking at the code. Included here in case somebody else hits this.

class CreateErrors < ActiveRecord::Migration
  def change
    create_table :errors do |t|
      t.string :class_name
      t.string :status
      t.text :message
      t.text :trace
      t.string :target
      t.string :referrer
      t.text :params
      t.string :user_agent
      t.timestamps
    end
  end
end

Using routes

Hello!
When my site fires a 400 error and renders within the application layout I get this error:

Completed 500 Internal Server Error in 212ms (ActiveRecord: 0.0ms)
Error during failsafe response: undefined local variable or method `root_path' for #<#<Class:0x007fd0c0409938>:0x007fd0c24946d0>

I have a _header.html.erb that uses the link_to tag with the root_path as the link. Is there a way around this? I also tried changing the default layout for 4xx errors but it still used my application layout.

Thanks for creating this awesome gem and thanks for the help!
-- Tad

Possible Unicorn issue?

I have a unicorn server running exception_handler. It works fine in development but when I push to staging I get a bad gateway error. Upon inspecting the unicorn.log file I see that the problem is a NoMethodError generated by the exception handler gem. Not sure what's up honestly.

E, [2015-04-07T07:41:09.893741 #3482] ERROR -- : undefined method `setup' for ExceptionHandler:Module (NoMethodError)
/home/deployer/apps/taxalli/releases/20150407113904/config/initializers/exception_handler.rb:6:in `<top (required)>'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/engine.rb:648:in `block in load_config_initializer'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/notifications.rb:161:in `instrument'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/engine.rb:647:in `load_config_initializer'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/engine.rb:611:in `each'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/engine.rb:611:in `block in <class:Engine>'
/usr/local/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
/usr/local/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
/usr/local/lib/ruby/2.0.0/tsort.rb:210:in `block (2 levels) in each_strongly_connected_component_from'
/usr/local/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
/usr/local/lib/ruby/2.0.0/tsort.rb:209:in `block in each_strongly_connected_component_from'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/initializable.rb:44:in `each'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/initializable.rb:44:in `tsort_each_child'
/usr/local/lib/ruby/2.0.0/tsort.rb:203:in `each_strongly_connected_component_from'
/usr/local/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
/usr/local/lib/ruby/2.0.0/tsort.rb:180:in `each'
/usr/local/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
/usr/local/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/initializable.rb:54:in `run_initializers'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/application.rb:288:in `initialize!'
/home/deployer/apps/taxalli/releases/20150407113904/config/environment.rb:5:in `<top (required)>'
config.ru:4:in `require'
config.ru:4:in `block in <main>'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn.rb:48:in `eval'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn.rb:48:in `block in builder'

/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn.rb:48:in `block in builder'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:750:in `call'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:750:in `build_app!'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:623:in `init_worker_process'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:643:in `worker_loop'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:527:in `spawn_missing_workers'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:538:in `maintain_worker_count'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/lib/unicorn/http_server.rb:303:in `join'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/gems/unicorn-4.7.0/bin/unicorn:126:in `<top (required)>'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/bin/unicorn:23:in `load'
/home/deployer/apps/taxalli/shared/bundle/ruby/2.0.0/bin/unicorn:23:in `<main>'                                               

Need to rewrite repo without huge files

Issue #41 was not addressed
The repository needs to be rewritten to exclude big files (or at least use git-lfs)

Currently this project is very hard to maintain, only cloning the repo took 30 minutes for me (speed limited by github, not my network) and I don't even want to consider adding this to a production environment.

Please avoid committing big files directly. You can have a look at https://rtyley.github.io/bfg-repo-cleaner/ or https://help.github.com/articles/removing-sensitive-data-from-a-repository/ to clean the mess.

The repo is 1.2 GB

Excessive memory usage on Heroku

I got this working on Heroku (thanks for the great gem!) However, now that it's running, it tends to eat up a ton of memory. It seems like a gem that's doing something relatively straightforward like this shouldn't take up 100MB+ of memory on Heroku, so perhaps there's some issue with it.

I use Scout on Heroku to check memory usage, and this gem is using more memory than any other page in my app by far, so it'd be awesome if you could figure out what's going on. That said, the dump from Scout didn't help me much in figuring out what was up - here's what it tells me:

Router/Rails
1 call
100%
exception_handler/exceptions/show
1 call
0%
...
Middleware
1 call
0%
Controller
1 call
0%
RedirectRule#find
SQL
1 call
0%

As you can see, "Router/Rails" appears to be the culprit, but I'm not sure what to do about that. None of my other pages see this kind of memory increase in the Router. Any ideas? Let me know if you need more info.

mail configuration

In config file there is

config.email

but if i activated i get this error

undefined method `email='

json error message for api

when I make a json call to app it properly gives { "status":"404"} but no json message is displayed for 500 and other errors but gives "500 Internal Server Error
If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong." Any idea for returning proper json messages for 500 and errors and other, with details. I'm new to rails

Mongoid support

I see no mention of Mongoid anywhere. Is it possible to work with Mongoid at all ? (Even if the database logging doesn't work yet ?)

EDIT -

The current version will cause a wonderful exception (haha sorry about that) when started with a Mongoid-backed DB with default configuration. Adding...

config.exception_handler = {
    db: false
  }

...doesn't seem to help.

Here's the top of my stack trace

[Rails root]/app/models/exception_handler/error.rb:2:in `<module:ExceptionHandler>': uninitialized constant ExceptionHandler::ActiveRecord (NameError)
        from [Rails root]/app/models/exception_handler/error.rb:1:in `<top (required)>'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies/interlock.rb:12:in `block in loading'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/concurrency/share_lock.rb:117:in `exclusive'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.0.beta3/lib/active_support/dependencies/interlock.rb:11:in `loading'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/engine.rb:476:in `block (2 levels) in eager_load!'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/engine.rb:475:in `each'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/engine.rb:475:in `block in eager_load!'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/engine.rb:473:in `each'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/engine.rb:473:in `eager_load!'
        from [Rails root]/config.ru:6:in `block in <main>'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:55:in `instance_eval'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:55:in `initialize'
        from [Rails root]/config.ru:in `new'
        from [Rails root]/config.ru:in `<main>'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:49:in `eval'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:49:in `new_from_string'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/builder.rb:40:in `parse_file'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/server.rb:318:in `build_app_and_options_from_config'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rack-2.0.0.alpha/lib/rack/server.rb:218:in `app'
        from C:/Dev/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.0.beta3/lib/rails/commands/server.rb:58:in `app'

whats the deal with usable?

hi,

what should we do with usable_type and usable_id in db?

error.rb

belongs_to :usable, polymorphic: true

is there any documenation?

Error when enabled; "Missing template mailers/layouts/mailer with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :jbuilder]}. Searched in:..."

I'm now getting this in production and dev, when I have it enabled. I generated the views, with your generator. It's throwing at line 100, in your exception model:

after_initialize Proc.new { |e| ExceptionHandler::ExceptionMailer.new_exception(e).deliver } if ExceptionHandler.config.try(:email).try(:is_a?, String)

Also, it's not saving the source exception to the db prior to this.

Here's my config:

config.exception_handler = {
        dev:    true, # => defaults to "false" for dev mode
        db:     true, # => defaults to :errors if true, else use "table_name" / :table_name
        email: 	'[email protected]', # => requires string email and ActionMailer
        layouts: {
            # => nil inherits from ApplicationController
            # => 4xx errors should be nil
            # => 5xx errors should be "exception" but can be nil if explicitly defined
            404 => "exception",
            401 => "exception",
            403 => "exception",
            500 => "exception",
            501 => "exception",
            502 => "exception",
            503 => "exception",
            504 => "exception",
            505 => "exception",
            507 => "exception",
            510 => "exception"
        }
    }

Not working with Heroku?

Hi, the gem 0.5.1 is working fine locally - great work! - however it does not catch any exceptions when I deploy to Heroku. Any clue? Rails version is 4.2 and ruby-2.2.4

Cheers!

Not working on heroku

Hi

I installed this gem. Works like a charm in dev but not in production on heroku.
I have
config.consider_all_requests_local = false
in my production.rb file, full config file below.

Your help is appreciated

Thanks
Youssef

  # Settings specified here will take precedence over those in config/application.rb.


  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = false

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable serving static files from the `/public` folder by default since
  # Apache or NGINX already handles this.
  config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Mount Action Cable outside main process or domain
  # config.action_cable.mount_path = nil
  # config.action_cable.url = 'wss://example.com/cable'
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  config.force_ssl = true

  # Use the lowest log level to ensure availability of diagnostic information
  # when problems arise.
  config.log_level = :debug

  # Prepend all log lines with the following tags.
  config.log_tags = [ :request_id ]

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Use a real queuing backend for Active Job (and separate queues per environment)
  # config.active_job.queue_adapter     = :resque
  # config.active_job.queue_name_prefix = "testapp_#{Rails.env}"
  config.action_mailer.perform_caching = false

##### Config for sending emails
  config.action_mailer.smtp_settings = {
    address: "smtp.xxx.com",
    port: 587,
    domain: Rails.application.secrets.domain_name,
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: Rails.application.secrets.email_provider_username,
    password: Rails.application.secrets.email_provider_password
  }
  # ActionMailer Config
  config.action_mailer.default_url_options = { :host => Rails.application.secrets.domain_name }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
  # Send email in development mode?
  config.action_mailer.perform_deliveries = true

  config.action_mailer.default_options = { 
    from: 'xxx <[email protected]>',
  }

##############

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Use a different logger for distributed setups.
  # require 'syslog/logger'
  # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger = ActiveSupport::TaggedLogging.new(logger)
  end

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false




end```

It does not work for me.

Rails 4.2.6
ruby 2.3.0p0

I'm following the instructions:

  • Installed gem
  • Added the config.exception_handler in application.rb
  • Execute rails generate exception_handler:views -v views controllers

Is there anything else I need to do? This is far from plug and play.

Both 404's and 500's error message's not working through exception_handler gem correclty

I'm only seeing the error message:

500 Internal Server Error
If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong.

When hitting both a 404, or a 500 error.

Here's a stacktrace for my app.

ActiveRecord::RecordNotFound (Couldn't find User with 'id'=12 [WHERE users.account_id = ?]):
app/controllers/users_controller.rb:10:in `show'

Processing by ExceptionHandler::ExceptionController#show as HTML
Parameters: {"id"=>"12"}
Account Load (0.4ms) SELECT accounts.* FROM accounts WHERE accounts.subdomain = 'ematoda' ORDER BY accounts.id ASC LIMIT 1
Rendered exception_handler/exception/show.html.erb within layouts/application (0.1ms)
(0.5ms) SELECT COUNT(*) FROM roles INNER JOIN users_roles ON roles.id = users_roles.role_id WHERE users_roles.user_id = 1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))
Completed 500 Internal Server Error in 104ms
Error during failsafe response: This action failed the check_authorization because it does not authorize_resource. Add skip_authorization_check to bypass this check.
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/cancan-1.6.10/lib/cancan/controller_additions.rb:261:in block in check_authorization' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:440:ininstance_exec'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:440:in block in make_lambda' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:231:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:231:in block in halting' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:229:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:229:in block in halting' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:229:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:229:in block in halting' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:166:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:166:in block in halting' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:166:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:166:in block in halting' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:166:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:166:in block in halting' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:86:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/callbacks.rb:86:in run_callbacks' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/abstract_controller/callbacks.rb:19:inprocess_action'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_controller/metal/rescue.rb:29:in process_action' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_controller/metal/instrumentation.rb:31:inblock in process_action'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/notifications.rb:159:in block in instrument' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/notifications/instrumenter.rb:20:ininstrument'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/notifications.rb:159:in instrument' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_controller/metal/instrumentation.rb:30:inprocess_action'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_controller/metal/params_wrapper.rb:250:in process_action' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activerecord-4.1.0.rc1/lib/active_record/railties/controller_runtime.rb:18:inprocess_action'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/abstract_controller/base.rb:136:in process' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionview-4.1.0.rc1/lib/action_view/rendering.rb:30:inprocess'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_controller/metal.rb:195:in dispatch' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_controller/metal/rack_delegation.rb:13:indispatch'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_controller/metal.rb:231:in block in action' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/exception_handler-0.3.0/lib/exception_handler.rb:20:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/exception_handler-0.3.0/lib/exception_handler.rb:20:in block (2 levels) in <class:Exceptions>' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_dispatch/middleware/show_exceptions.rb:46:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_dispatch/middleware/show_exceptions.rb:46:in render_exception' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_dispatch/middleware/show_exceptions.rb:35:inrescue in call'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_dispatch/middleware/show_exceptions.rb:30:in call' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/railties-4.1.0.rc1/lib/rails/rack/logger.rb:38:incall_app'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/railties-4.1.0.rc1/lib/rails/rack/logger.rb:20:in block in call' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/tagged_logging.rb:68:inblock in tagged'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/tagged_logging.rb:26:in tagged' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/tagged_logging.rb:68:intagged'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/railties-4.1.0.rc1/lib/rails/rack/logger.rb:20:in call' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/quiet_assets-1.0.2/lib/quiet_assets.rb:18:incall_with_quiet_assets'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_dispatch/middleware/request_id.rb:21:in call' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/rack-1.5.2/lib/rack/runtime.rb:17:in call' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/activesupport-4.1.0.rc1/lib/active_support/cache/strategy/local_cache.rb:87:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/rack-1.5.2/lib/rack/lock.rb:17:in call' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/actionpack-4.1.0.rc1/lib/action_dispatch/middleware/static.rb:64:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in call' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/railties-4.1.0.rc1/lib/rails/engine.rb:515:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/railties-4.1.0.rc1/lib/rails/application.rb:142:in call' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/rack-1.5.2/lib/rack/content_length.rb:14:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/puma-2.7.1/lib/puma/server.rb:486:in handle_request' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/puma-2.7.1/lib/puma/server.rb:357:inprocess_client'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/puma-2.7.1/lib/puma/server.rb:250:in block in run' /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/puma-2.7.1/lib/puma/thread_pool.rb:92:incall'
/Users/tomcaflisch/.rvm/gems/ruby-2.1.1@trakd/gems/puma-2.7.1/lib/puma/thread_pool.rb:92:in `block in spawn_thread'

Readme is impractical

Thanks for the gem.

But the readme is so fancy that is impractical. May I ask why there are pictures instead of regular code blocks which you can copy/paste them ?

Error when running rails generate exception_handler:install

I got the following error when trying to run rails generate exception_handler:install based on

http://www.rubydoc.info/gems/exception_handler/0.3.45

I realize that is an old doc. I am just trying to set things up so the config files are available

 chris@chris-VirtualBox:~/Documents/RailsProjects/LineIndex$ rails generate exception_handler:install
 Running via Spring preloader in process 30401
 Expected string default value for '--serializer'; got true (boolean)
 Could not find generator 'exception_handler:install'. Maybe you meant 'exception_handler:views', 'responders:install' or 'integration_test'
 Run `rails generate --help` for more options.

Running ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
Rails 5.0.2

bundle info gives

chris@chris-VirtualBox:~/Documents/RailsProjects/LineIndex$ bundle info exception_handler
  * exception_handler (0.7.7.0)
	Summary: Rails gem to show custom error pages in production. Also logs errors in db & sends notification emails
	Homepage: https://github.com/richpeck/exception_handler
	Path: /home/chris/.rvm/gems/ruby-2.4.1/gems/exception_handler-0.7.7.0

@exception.status == "500" is always false (even during a 500 error)

This is probably due to something I've set up in my application (newish to Rails, and Rails 5 doubly so), but:

None of the logic contained within the div tag on the show page ever triggers, as
if @exception.status == "500" is always false.

(Here is the div tag for reference):

<%= 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 %>

Changing this to if @exception.status == 500 works
(no quotes, comparing against an integer instead of a string)

I added the following span tags to the show page, to test whether the new comparison works:

  <span style="color:white;"><%= @exception.status == "500" %></span>
  <br />
  <span style="color:white;"><%= @exception.status == 500 %></span>

Below, you can see that it still regards the comparison using "500" as false,
but evaluates the comparion using 500 as true.

screen shot 2017-07-10 at 5 03 44 pm

Is this something unique to Rails 5? Perhaps some setting I toggled/forgot to toggle somewhere in a config file?

Changing "500" to 500 works just fine and allows me to go about my day, so this is purely motivated by curiosity.

Thanks!

Migrations error out on Rails 4

ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base

When I set db: true and attempt a rake db:migrate it fails out with the above error. I've looked at the migration in the library and the syntax is pretty alien. Maybe its a rails 5 thing? Needless to say, it doesn't seem to work.

Is there a work around? I cant upgrade to rails 5 as its a rather huge existing codebase, but perhaps a regular rails 4 style migration migiht fix it?

How to use a custom controller

I'm trying to use this gem with spree, but for the site nav etc to work we need the controller to use the Spree module and the controller also needs to inherit from Spree::StoreController. Is there a way to do this?

Migration tries to recreate table if it already exists

As per the documentation, for ActiveRecord integration, all that is required is to run rails db:migrate This also adds the errors table in to the schema.rb file.

The problem is then whenever anyone calls rails db:reset it gets the database configuration from the schema.rb and creates the errors table.

When db:migrate is used again (such as to complete a later migration), it tries to create the errors table again throwing a duplicate table error.

Steps to reproduce

  1. run rails db:migrate to create the errors table and update schema.rb
  2. run rails db:reset to reset the database as per the schema file
  3. run rails db:migrate again to get the exception handler gem to try and recreate the table again

Expected behaviour

Exception handler should know that a table with the same name (and/or same columns) already exists and not try to recreate the table

Actual behaviour

Exception handler tries to recreate the errors table

System Configuration

Ruby 2.2.4
Rails 5.0.1
PostgreSQL 9.5.4

What should I do with the files in public folder, e.g. 404.html etc

Hi, I've successfully integrated exception_handler gem. It's a nice gem.

But I still have files in public folders e.g. 404.html, 422.html and others.
Should I remove these files? Or should I use curl and save the pretty version of these. How should I raise the correct error exceptions which exception_handler gem handles to generate 500, 422 and 404 pages at runtime on Heroku? or Should I just remove these pages?
Also, I need to remove assets provided by exception_handler, I'm using my own assets and it only increases the slug size.

Thanks,

Wrong HTTP status

I think you should use

def show
  render status: @status
end

instead of

respond_with status: @status

in your ExceptionController

because now errors are generated with 200 HTTP status

My solution will fix this problem

Ironically localhost:3000/404 still gives me the old error page; also, cant redirect 500 errors to new 404 page =[

localhost:3000/404 gives the standard error page. I've been struggling to change this in routes.rb, maybe someone can tell me what I'm doing wrong.
screen shot 2018-03-20 at 10 25 37 pm

Every other page gives me my 404 as expected (i'm very pleased overall, besides the exception ive mentioned above):
screen shot 2018-03-20 at 10 26 12 pm

But also, I don't get my new error page with 500 errors. I get the follow:
screen shot 2018-03-20 at 10 31 38 pm

How can i make it so that 500 goes to the same page as 400?

What to do with non html formats (missing images)?

Hello, thanks indeed for the great gem!

Have been struggling to figure out how to handle 404 pages for missing images and other non html, json or xml requests.

Currently, if I request file.png, then the Exception App handles the request and I get

Processing by ExceptionHandler::ExceptionController#show as PNG
Completed 500 Internal Server Error in 81ms (ActiveRecord: 3.6ms)

Error during failsafe response: Missing template exception_handler/exception/show, alchemy/base/show, application/show with {:locale=>[:en], :formats=>[:png], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :rabl], :versions=>[:v10, :v9, :v8, :v7, :v6, :v5, :v4, :v3, :v2, :v1]}

Searched in:

If I use respond_with or respond_to :html in the controller, then I get

Processing by ExceptionHandler::ExceptionController#show as PNG

Completed 406 Not Acceptable in 16ms (ActiveRecord: 0.0ms)

Error during failsafe response: ActionController::UnknownFormat

.. and I get a 500 error in the browser instead of the 406 : (

Note, I'm using a slightly older version of the gem - 0.5.1, but I don't think going with a newer version of it will make a difference, as I already tested out the latest exception controller with the respond_with. Rails is 4.2.

I have a feeling I am missing something, as I couldn't find anyone else complain about something similar. Any ideas?

Thank you

You guys just ruined my whole project

I just wanted to update error page view so I rendered them. All my theme settings css files overwriten. Almost nothing is working.

How can i somehow ROLLBACK your actions. You have no idea how bad its for me.

Send exception full trace in email

How can i also send full details of error in email so that I could figure out where it actually happened? rather than just seeing the error description?

Missing Rails 4.2+ dependency

Hello,
thanks for the great gem.

I was testing it in development environment (config.consider_all_requests_local = false) under Rails 4.2.5 and got an error when testing a RouteNotFound Exception that said:

Error during failsafe response: The controller-level `respond_to' feature has been extracted to the `responders` gem. Add it to your Gemfile to continue using this feature:
  gem 'responders', '~> 2.0'
Consult the Rails upgrade guide for details.

It seems respond_with got removed in Rails >4.2 and is used in exception_handler...
Like instructed I installed the responders gem (and ran rails g responders:install)
Then it was working. Maybe you should add responders to exception_handler's dependencies or in the installation instruction?

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.