diff --git a/lib/concepts/class_member/operations/create.rb b/lib/concepts/class_member/operations/create.rb index b156dd3a..ec0477cf 100644 --- a/lib/concepts/class_member/operations/create.rb +++ b/lib/concepts/class_member/operations/create.rb @@ -45,14 +45,14 @@ def create_class_students(school_class:, students:, response:) end def handle_class_teacher_error(exception, class_teacher, teacher, response) - Sentry.capture_exception(exception) + Sentry.capture_exception(exception) unless exception.message.include?('has already been taken') errors = class_teacher.errors.full_messages.join(',') response[:error] ||= "Error creating one or more class members - see 'errors' key for details" response[:errors][teacher.id] = "Error creating class member for teacher_id #{teacher.id}: #{errors}" end def handle_class_student_error(exception, class_student, student, response) - Sentry.capture_exception(exception) + Sentry.capture_exception(exception) unless exception.message.include?('has already been taken') errors = class_student.errors.full_messages.join(',') response[:error] ||= "Error creating one or more class members - see 'errors' key for details" response[:errors][student.id] = "Error creating class member for student_id #{student.id}: #{errors}" diff --git a/spec/concepts/class_member/create_spec.rb b/spec/concepts/class_member/create_spec.rb index ef761eb5..e6b67b18 100644 --- a/spec/concepts/class_member/create_spec.rb +++ b/spec/concepts/class_member/create_spec.rb @@ -187,5 +187,13 @@ end end end + + context 'when duplicate validation errors occur' do + it 'does not send the exception to Sentry' do + duplicate_student = students.first + described_class.call(school_class:, students: [duplicate_student, duplicate_student]) + expect(Sentry).not_to have_received(:capture_exception) + end + end end end