Skip to content
Open
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
10 changes: 5 additions & 5 deletions lib/concepts/school_student/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module SchoolStudent
class Create
class << self
def call(school:, school_student_params:, token:)
response = OperationResponse.new
response[:student_id] = create_student(school, school_student_params, token)
response
student_id = create_student(school, school_student_params, token)
OperationResponse[student_id:]
rescue ProfileApiClient::Student422Error => e
OperationResponse[error: e.to_s]
rescue StandardError => e
Sentry.capture_exception(e)
response[:error] = e.to_s
response
OperationResponse[error: e.to_s]
end

private
Expand Down
19 changes: 15 additions & 4 deletions spec/concepts/school_student/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,28 @@
end
end

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

before do
allow(ProfileApiClient).to receive(:create_school_student).and_raise(exception)
allow(Sentry).to receive(:capture_exception)
end

it 'adds a useful error message' do
it 'returns the translatable error code' do
response = described_class.call(school:, school_student_params:, token:)
expect(response[:error]).to eq("something's up with the username")
expect(response[:error]).to eq('isComplex')
end

it 'does not send the expected validation error to Sentry' do
described_class.call(school:, school_student_params:, token:)
expect(Sentry).not_to have_received(:capture_exception)
end
end

Expand Down
Loading