No commit activity in last 3 years
No release in over 3 years
Transform exceptions and send to a crash reporter.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 2.2.33
>= 12.3.3
>= 3.0

Runtime

 Project Readme

exception-transformer Gem Version

Add exceptions to be transformed in handle_exceptions block.

Battle-tested in production at Privy.

Configuration

Crash Reporter

A crash reporter should be configured during the gem setup.

ExceptionTransformer.configure do |config|
  config.reporter = proc { |e| Raven.capture_exception(e) }
end

Documentation

See API dcumentation at https://www.rubydoc.info/gems/exception_transformer.

Examples

Transform several errors to a single error

transform_exceptions FooError, BazError, to: BarError

Transform a single error based on it's message

transform_exceptions FooError, where: {
  /Invalid API key/i => BarError,
  :default => RuntimeError
}

To prevent all errors being caught via the :default branch, pass use_default: false to handle_exceptions.

Validate a response with a Proc that takes two parameters

The first parameter is the response, and the second is the calling method.

transform_exceptions validate: proc { |response, action| ... }

Inspect an error with a Proc that takes two parameters

The first parameter is the error, and the second is the calling method.

transform_exceptions with: proc { |err, action| ... }