Transform your exceptions.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.travis.yml
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile
exception_transformer.gemspec

README.md

exception-transformer

Add exceptions to be transformed in handle_exceptions block.

Battle-tested in production at Privy.

Examples

  1. Transform several errors to a single error:
transform_exceptions FooError, BazError, to: BarError
  1. 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.

  1. 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| ... }
  1. 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| ... }

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