Skip to content

Commit

Permalink
Redirect the candidate to the correct error page
Browse files Browse the repository at this point in the history
There are two types of errors the candidate can encounter when using one
login. Typical 500 errors and when a user uses the wrong email address

We need to know what error the candidate gets to redirect them to the
correct page.

Prior to this change we are redirecting the candidate to wrong_email
error page even if it's a 500 error page.

This commit redirects the user to the correct error page
  • Loading branch information
CatalinVoineag committed Jan 24, 2025
1 parent 319654c commit b56baac
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 b56baac

Please sign in to comment.