From 99ad008f9269d0b2f94e423bcaeffd6118e2e60f Mon Sep 17 00:00:00 2001 From: Hicham Boushaba Date: Tue, 19 Nov 2024 11:46:19 +0100 Subject: [PATCH] Use guard instead of if else --- .../WPComLogin/WPComEmailLoginViewModel.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/WooCommerce/Classes/Authentication/WPComLogin/WPComEmailLoginViewModel.swift b/WooCommerce/Classes/Authentication/WPComLogin/WPComEmailLoginViewModel.swift index 7528dace106..d5ef7b62337 100644 --- a/WooCommerce/Classes/Authentication/WPComLogin/WPComEmailLoginViewModel.swift +++ b/WooCommerce/Classes/Authentication/WPComLogin/WPComEmailLoginViewModel.swift @@ -87,16 +87,16 @@ final class WPComEmailLoginViewModel: ObservableObject { } await startAuthentication(email: email, isPasswordlessAccount: passwordless) } catch { - if allowAccountCreation, - let apiError = error as? WordPressAPIError, - 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, + 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) } }