From d01a0dadc89139c02312d66d63a115bb3b24ed7d Mon Sep 17 00:00:00 2001 From: Lihan Li Date: Tue, 1 Nov 2016 15:15:10 -0400 Subject: [PATCH 1/2] send validation error to sentry --- app/controllers/v0/education_benefits_claims_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/v0/education_benefits_claims_controller.rb b/app/controllers/v0/education_benefits_claims_controller.rb index f6fb9768785..3f42e6c4d95 100644 --- a/app/controllers/v0/education_benefits_claims_controller.rb +++ b/app/controllers/v0/education_benefits_claims_controller.rb @@ -7,7 +7,12 @@ def create education_benefits_claim = EducationBenefitsClaim.new(education_benefits_claim_params) unless education_benefits_claim.save - logger.error(education_benefits_claim.errors.full_messages.join(', ')) + validation_error = education_benefits_claim.errors.full_messages.join(', ') + + Raven.tags_context(validation: 'education_benefits_claim') + Raven.capture_exception(validation_error) + + logger.error(validation_error) raise Common::Exceptions::ValidationErrors, education_benefits_claim end From eebcdbb549e99a9e62be1164b79183d6dc725aa6 Mon Sep 17 00:00:00 2001 From: Lihan Li Date: Tue, 1 Nov 2016 15:23:19 -0400 Subject: [PATCH 2/2] test raven capture exception --- spec/request/education_benefits_claims_request_spec.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spec/request/education_benefits_claims_request_spec.rb b/spec/request/education_benefits_claims_request_spec.rb index 50caeb4131d..51acf6037d9 100644 --- a/spec/request/education_benefits_claims_request_spec.rb +++ b/spec/request/education_benefits_claims_request_spec.rb @@ -78,8 +78,13 @@ it 'should log the validation errors' do education_benefits_claim = EducationBenefitsClaim.new(params[:educationBenefitsClaim]) education_benefits_claim.valid? + validation_error = education_benefits_claim.errors.full_messages.join(', ') + allow(Rails.logger).to receive(:error) - expect(Rails.logger).to receive(:error).with(education_benefits_claim.errors.full_messages.join(', ')).once + expect(Rails.logger).to receive(:error).with(validation_error).once + + expect(Raven).to receive(:tags_context).once.with(validation: 'education_benefits_claim') + expect(Raven).to receive(:capture_exception).once.with(validation_error) subject end