Last active
July 27, 2016 03:41
-
-
Save AlexandrBasan/d7d6431e47ed84097eb03cfbe0a1b080 to your computer and use it in GitHub Desktop.
ExceptionDatabaseSaver middleware for Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_dependency "lib/exception_database_saver.rb" | |
config.middleware.use ExceptionDatabaseSaver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Easy custom middleware to save all Exceptions raised by Rails to Audit table to DB | |
# Created by Alexandr Basan | |
class ExceptionDatabaseSaver | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
@app.call(env) | |
rescue Exception => exception | |
Audit.create!( | |
:auditable => 0, | |
:user => 0, | |
:action => "error", | |
:comment => "Exception was rised", | |
:audited_changes => "#{exception}. #{exception.backtrace}" | |
) | |
raise exception | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment