Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/concepts/class_member/operations/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
8 changes: 8 additions & 0 deletions spec/concepts/class_member/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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