Skip to content

Commit

Permalink
Use guard instead of if else
Browse files Browse the repository at this point in the history
  • Loading branch information
hichamboushaba committed Nov 19, 2024
1 parent aa7a587 commit 99ad008
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ final class WPComEmailLoginViewModel: ObservableObject {
}
await startAuthentication(email: email, isPasswordlessAccount: passwordless)
} catch {
if allowAccountCreation,
let apiError = error as? WordPressAPIError<WordPressComRestApiEndpointError>,
case let .endpointError(endpointError) = apiError,
endpointError.apiErrorCode == Constants.unknownUserErrorCode {
// The user does not exist yet, trigger magic link flow for account creation
await requestAuthenticationLink(email: email, forAccountCreation: true)
} else {
guard allowAccountCreation,
let apiError = error as? WordPressAPIError<WordPressComRestApiEndpointError>,
case .endpointError(let endpointError) = apiError,
endpointError.apiErrorCode == Constants.unknownUserErrorCode else {
analytics.track(event: .JetpackSetup.loginFlow(step: .emailAddress, failure: error))
onError(error.localizedDescription)
return
}

await requestAuthenticationLink(email: email, forAccountCreation: true)
}
}

Expand Down

0 comments on commit 99ad008

Please sign in to comment.