Skip to content

Commit c7f621c

Browse files
authored
Stop reporting expected student validation errors to Sentry (#938)
Related to Sentry issue RaspberryPiFoundation/digital-editor-issues#1583 ## Points for consideration: - No security impact. - No performance impact. ## What's changed? - When someone tries to create a student with: - Username already taken - Password matches the username - Password too short - Missing or invalid student details Profile API returns an isComplex validation error. - This is an expected error that is shown to the user, but we were also sending it to Sentry. - This change handles student validation errors separately, so they are no longer sent to Sentry (since i don't think they add value and cause noise).. ## Steps to perform after deploying to production No additional steps are required. There are no migrations, configuration changes, or data backfills.
1 parent 173fdbe commit c7f621c

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

lib/concepts/school_student/create.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module SchoolStudent
44
class Create
55
class << self
66
def call(school:, school_student_params:, token:)
7-
response = OperationResponse.new
8-
response[:student_id] = create_student(school, school_student_params, token)
9-
response
7+
student_id = create_student(school, school_student_params, token)
8+
OperationResponse[student_id:]
9+
rescue ProfileApiClient::Student422Error => e
10+
OperationResponse[error: e.to_s]
1011
rescue StandardError => e
1112
Sentry.capture_exception(e)
12-
response[:error] = e.to_s
13-
response
13+
OperationResponse[error: e.to_s]
1414
end
1515

1616
private

spec/concepts/school_student/create_spec.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,28 @@
7777
end
7878
end
7979

80-
context 'when the student cannot be created in profile api because of a 422 response' do
81-
let(:error) { { 'message' => "something's up with the username" } }
80+
context 'when Profile API rejects the student details' do
81+
let(:error) do
82+
{
83+
'errorCode' => 'isComplex',
84+
'message' => 'Password is too simple'
85+
}
86+
end
8287
let(:exception) { ProfileApiClient::Student422Error.new(error) }
8388

8489
before do
8590
allow(ProfileApiClient).to receive(:create_school_student).and_raise(exception)
91+
allow(Sentry).to receive(:capture_exception)
8692
end
8793

88-
it 'adds a useful error message' do
94+
it 'returns the translatable error code' do
8995
response = described_class.call(school:, school_student_params:, token:)
90-
expect(response[:error]).to eq("something's up with the username")
96+
expect(response[:error]).to eq('isComplex')
97+
end
98+
99+
it 'does not send the expected validation error to Sentry' do
100+
described_class.call(school:, school_student_params:, token:)
101+
expect(Sentry).not_to have_received(:capture_exception)
91102
end
92103
end
93104

0 commit comments

Comments
 (0)