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
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]
Comment on lines 11 to +13

@zetter-rpf zetter-rpf Jul 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be changed as part of this, but I'm unsure if there is value in having this here since there's already something in the api controller that converts errors to an API response. I think this would only be useful if there there is a need in this controller that this is used to render errors in a different format to what the base api controller does.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. We can create a separate ticket to discuss the exact cleanup later.

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