Skip to content

Commit ec87a3a

Browse files
authored
977: Ignore class member validation errors in sentry (#605)
## Status RaspberryPiFoundation/digital-editor-issues#977 ## What's changed? Ensures validation errors aren't raised for ClassMembers in Sentry, this is especially important for the importer where a re-import would trigger potentially hundreds of these ## Steps to perform after deploying to production N/A
1 parent 2fc0f23 commit ec87a3a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/concepts/class_member/operations/create.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ def create_class_students(school_class:, students:, response:)
4545
end
4646

4747
def handle_class_teacher_error(exception, class_teacher, teacher, response)
48-
Sentry.capture_exception(exception)
48+
Sentry.capture_exception(exception) unless exception.message.include?('has already been taken')
4949
errors = class_teacher.errors.full_messages.join(',')
5050
response[:error] ||= "Error creating one or more class members - see 'errors' key for details"
5151
response[:errors][teacher.id] = "Error creating class member for teacher_id #{teacher.id}: #{errors}"
5252
end
5353

5454
def handle_class_student_error(exception, class_student, student, response)
55-
Sentry.capture_exception(exception)
55+
Sentry.capture_exception(exception) unless exception.message.include?('has already been taken')
5656
errors = class_student.errors.full_messages.join(',')
5757
response[:error] ||= "Error creating one or more class members - see 'errors' key for details"
5858
response[:errors][student.id] = "Error creating class member for student_id #{student.id}: #{errors}"

spec/concepts/class_member/create_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,13 @@
187187
end
188188
end
189189
end
190+
191+
context 'when duplicate validation errors occur' do
192+
it 'does not send the exception to Sentry' do
193+
duplicate_student = students.first
194+
described_class.call(school_class:, students: [duplicate_student, duplicate_student])
195+
expect(Sentry).not_to have_received(:capture_exception)
196+
end
197+
end
190198
end
191199
end

0 commit comments

Comments
 (0)