LiquidErrorHandler
Configure error handling hooks for the Liquid templating language for Ruby.
Installation
Add this line to your application's Gemfile:
gem 'liquid_error_handler', '~> 0.1.0'
Usage
Register an error handler, for example in a Rails initializer. Error handlers should be callable and will receive the error as an argument.
# config/initializers/liquid_error_handler.rb
LiquidErrorHandler.register_handler do |error|
Rails.logger.error("Liquid Error: #{error} #{error.backtrace}")
end
Use with libraries like Airbrake to send all Liquid errors to your error aggregation platform:
# config/initializers/liquid_error_handler.rb
LiquidErrorHandler.register_handler do |error|
Airbrake.notify(error) unless Rails.env.development? || Rails.env.test?
end
Disabling
LiquidErrorHandler can be disabled by setting the environment variable LIQUID_ERROR_HANDLER_DISABLE
to any value:
LIQUID_ERROR_HANDLER_DISABLE=1 rails server
Resetting
All error handlers can be removed by calling LiquidErrorHandler.reset
:
LiquidErrorHandler.reset