Skip to content

Commit

Permalink
Merge pull request #10299 from DFE-Digital/cv/one-login-redirect-to-e…
Browse files Browse the repository at this point in the history
…rror-page

Redirect the candidate to the correct error page
  • Loading branch information
CatalinVoineag authored Jan 24, 2025
2 parents 319654c + b56baac commit 00c172e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/controllers/one_login_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def callback
)

if e.is_a?(OneLoginUser::Error)
session_error.wrong_email_address!
session[:session_error_id] = session_error.id
Sentry.capture_message(
"One login session error, check session_error record #{session_error.id}",
Expand Down Expand Up @@ -73,8 +74,16 @@ def sign_out

def sign_out_complete
if session[:session_error_id].present?
session_error = SessionError.find_by(id: session[:session_error_id])
reset_session
redirect_to candidate_interface_wrong_email_address_path

path_to_error_page = if session_error&.wrong_email_address?
candidate_interface_wrong_email_address_path
else
internal_server_error_path
end

redirect_to path_to_error_page
else
redirect_to candidate_interface_create_account_or_sign_in_path
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/session_error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class SessionError < ApplicationRecord
belongs_to :candidate, optional: true

enum :error_type, {
internal: 'internal',
wrong_email_address: 'wrong_email_address',
}
end
5 changes: 5 additions & 0 deletions spec/requests/one_login_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@
)
expect(session[:session_error_id]).to eq(SessionError.last.id)
expect(response).to redirect_to(auth_one_login_sign_out_path)

# a failure will need to call sign_out_complete
get auth_one_login_sign_out_complete_path

expect(response).to redirect_to(internal_server_error_path)
end
end
end

0 comments on commit 00c172e

Please sign in to comment.