Notify Bugsnag on sign-up errors

This may lead to more error reports than we want to see. A not existing
email address may cause Bugsnag to be notified. If this happens, we can
rescue form these specific errors and only report the rest.
This commit is contained in:
Maikel Linke
2018-09-17 10:50:24 +10:00
parent 17d951f99d
commit 9dcc683dc0
4 changed files with 32 additions and 1 deletions

View File

@@ -1,3 +1,5 @@
require 'open_food_network/error_logger'
class UserRegistrationsController < Spree::UserRegistrationsController
before_filter :set_checkout_redirect, only: :create
@@ -21,7 +23,8 @@ class UserRegistrationsController < Spree::UserRegistrationsController
else
render_error(@user.errors)
end
rescue StandardError
rescue StandardError => error
OpenFoodNetwork::ErrorLogger.notify(error)
render_error(message: I18n.t('devise.user_registrations.spree_user.unknown_error'))
end

View File

@@ -0,0 +1,13 @@
# Our error logging API currently wraps Bugsnag.
# It makes us more flexible if we wanted to replace Bugsnag or change logging
# behaviour.
module OpenFoodNetwork
module ErrorLogger
# Tries to escalate the error to a developer.
# If Bugsnag is configured, it will notify it. It would be nice to implement
# some kind of fallback.
def self.notify(error)
Bugsnag.notify(error)
end
end
end

View File

@@ -31,6 +31,7 @@ describe UserRegistrationsController, type: :controller do
it "returns error when emailing fails" do
allow(Spree::UserMailer).to receive(:confirmation_instructions).and_raise("Some error")
expect(OpenFoodNetwork::ErrorLogger).to receive(:notify)
xhr :post, :create, spree_user: user_params, use_route: :spree

View File

@@ -0,0 +1,14 @@
require 'spec_helper'
require 'open_food_network/error_logger'
module OpenFoodNetwork
describe ErrorLogger do
let(:error) { StandardError.new("Test") }
it "notifies Bugsnag" do
expect(Bugsnag).to receive(:notify).with(error)
ErrorLogger.notify(error)
end
end
end