mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
13
lib/open_food_network/error_logger.rb
Normal file
13
lib/open_food_network/error_logger.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
|
||||
14
spec/lib/open_food_network/error_logger_spec.rb
Normal file
14
spec/lib/open_food_network/error_logger_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user