zapnap/resque_mailer — pull request #48 by adambird (2012-12-06 23:02:26+00:00)
Title: Custom error handling

Added `error_handler` attribute to `Resque::Mailer` module to allow a lambda to be passed for execution when an error occurs during `perform`

## Requirement

We use `AWS::SES` and occasionally addresses get blacklisted. I wanted to trap this occurrence and mark the email address as suspect. I also didn't want this error to bubble up to my `Resque` monitoring.

## Usage

Here's a simple case that logs AWS Response Errors but doesn't bubble the error up.

```ruby
Resque::Mailer.error_handler = lambda { |mailer, message, exception|
logger.error "#{exception.code} #{exception.message} when sending email to #{message.to.join(",")}", exception
raise exception unless exception.is_a?(AWS::SES::ResponseError) && exception.code == 400
}
```