LoginSignup
8
6

More than 5 years have passed since last update.

ExceptionNotifier.notify_exception で処理されない3つの Exception

Posted at

exception_notification v4.0.0 の話です。

v4.0.0から通知処理をバックグラウンド実行する、以下のようなコードが書けるようになりました。

begin
  some code...
rescue => e
  ExceptionNotifier.notify_exception(e)
end

これは便利なのですが、1点認識しておかないといけないことがあります。
ExceptionNotifier では以下の3つの Exception についてはデフォルトで処理しないようにハードコードされています。

  • ActiveRecord::RecordNotFound
  • AbstractController::ActionNotFound
  • ActionController::RoutingError

もしこれらを処理対象としたいのであれば、ここにあるように ignore_exceptions オプションを利用して、例えば下記のような定義をする必要があります。

Whatever::Application.config.middleware.use ExceptionNotification::Rack,
  :ignore_exceptions => '',
  :email => {
    :email_prefix         => "[Whatever] ",
    :sender_address       => %{"notifier" <notifier@example.com>},
    :exception_recipients => %w{exceptions@example.com}
  }
8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6