Add exceptions to be transformed in handle_exceptions
block.
Battle-tested in production at Privy.
A crash reporter should be configured during the gem setup.
ExceptionTransformer.configure do |config|
config.reporter = proc { |e| Raven.capture_exception(e) }
end
See API dcumentation at https://www.rubydoc.info/gems/exception_transformer.
transform_exceptions FooError, BazError, to: BarError
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
.
The first parameter is the response, and the second is the calling method.
transform_exceptions validate: proc { |response, action| ... }
The first parameter is the error, and the second is the calling method.
transform_exceptions with: proc { |err, action| ... }