Skip to content

Commit 9fafc53

Browse files
committed
Refactor error handling in ApplicationPasswordAuthorizationWebViewController and display errorUI instead of error alert
1 parent 4ae12d2 commit 9fafc53

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

WooCommerce/Classes/Authentication/Application Password/ApplicationPasswordAuthorizationWebViewController.swift

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -162,28 +162,14 @@ private extension ApplicationPasswordAuthorizationWebViewController {
162162
guard let url = try await viewModel.fetchAuthURL() else {
163163
DDLogError("⛔️ No authorization URL found for application passwords")
164164
analytics.track(.applicationPasswordAuthorizationURLNotAvailable)
165-
166-
let errorUI = applicationPasswordDisabledUI(for: viewModel.siteURL)
167-
// When the error view controller is popped, navigate to previous VC
168-
errorUI.navigationItem.leftBarButtonItem = UIBarButtonItem(
169-
image: UIImage(systemName: "chevron.backward"),
170-
style: .plain,
171-
target: self,
172-
action: #selector(navigateToPreviousViewController)
173-
)
174-
175-
// Push instead of present
176-
navigationController?.pushViewController(errorUI, animated: true)
177-
165+
navigateToErrorUI()
178166
return
179167
}
180168
loadAuthorizationPage(url: url)
181169
} catch {
182170
DDLogError("⛔️ Error fetching authorization URL for application passwords \(error)")
183171
analytics.track(.applicationPasswordAuthorizationURLFetchFailed, withError: error)
184-
showErrorAlert(message: Localization.errorFetchingAuthURL, onRetry: { [weak self] in
185-
self?.fetchAuthorizationURL()
186-
})
172+
navigateToErrorUI()
187173
}
188174
activityIndicator.stopAnimating()
189175
}
@@ -198,6 +184,19 @@ private extension ApplicationPasswordAuthorizationWebViewController {
198184
}
199185
}
200186

187+
private func navigateToErrorUI() {
188+
let errorUI = applicationPasswordDisabledUI(for: viewModel.siteURL)
189+
// When the error view controller is popped, navigate to previous VC
190+
errorUI.navigationItem.leftBarButtonItem = UIBarButtonItem(
191+
image: UIImage(systemName: "chevron.backward"),
192+
style: .plain,
193+
target: self,
194+
action: #selector(navigateToPreviousViewController)
195+
)
196+
// Push instead of present
197+
navigationController?.pushViewController(errorUI, animated: true)
198+
}
199+
201200
func loadAuthorizationPage(url: URL) {
202201
let parameters: [URLQueryItem] = [
203202
URLQueryItem(name: Constants.Query.appName, value: appName),
@@ -317,9 +316,5 @@ private extension ApplicationPasswordAuthorizationWebViewController {
317316
comment: "Error message displayed when application password authorization fails " +
318317
"during login due to the feature being disabled on the input site."
319318
)
320-
static let errorFetchingAuthURL = NSLocalizedString(
321-
"Failed to fetch the authorization URL for application passwords. Please try again.",
322-
comment: "Error message displayed when failed to fetch application password authorization URL during login"
323-
)
324319
}
325320
}

0 commit comments

Comments
 (0)