Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit f2ad89e

Browse files
Track error message even if the error has been handled by the host app.
1 parent c169358 commit f2ad89e

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -505,27 +505,41 @@ private extension SiteAddressViewController {
505505

506506
let err = self.originalErrorOrError(error: error as NSError)
507507

508+
let errorMessage: String? = {
509+
if let xmlrpcValidatorError = err as? WordPressOrgXMLRPCValidatorError {
510+
return xmlrpcValidatorError.localizedDescription
511+
} else if (err.domain == NSURLErrorDomain && err.code == NSURLErrorCannotFindHost) ||
512+
(err.domain == NSURLErrorDomain && err.code == NSURLErrorNetworkConnectionLost) {
513+
// NSURLErrorNetworkConnectionLost can be returned when an invalid URL is entered.
514+
let msg = NSLocalizedString(
515+
"The site at this address is not a WordPress site. For us to connect to it, the site must use WordPress.",
516+
comment: "Error message shown a URL does not point to an existing site.")
517+
return msg
518+
} else {
519+
return nil
520+
}
521+
}()
522+
508523
/// Check if the host app wants to provide custom UI to handle the error.
509524
/// If it does, insert the custom UI provided by the host app and exit early
510525
if self.authenticationDelegate.shouldHandleError(err) {
526+
527+
// Send the error to the host app
511528
self.authenticationDelegate.handleError(err) { customUI in
512529
self.pushCustomUI(customUI)
513530
}
514531

532+
// Track error message as failure
533+
if let message = errorMessage {
534+
self.tracker.track(failure: message)
535+
}
536+
537+
// Return as the error has been handled by the host app.
515538
return
516539
}
517540

518-
if let xmlrpcValidatorError = err as? WordPressOrgXMLRPCValidatorError {
519-
self.displayError(message: xmlrpcValidatorError.localizedDescription, moveVoiceOverFocus: true)
520-
521-
} else if (err.domain == NSURLErrorDomain && err.code == NSURLErrorCannotFindHost) ||
522-
(err.domain == NSURLErrorDomain && err.code == NSURLErrorNetworkConnectionLost) {
523-
// NSURLErrorNetworkConnectionLost can be returned when an invalid URL is entered.
524-
let msg = NSLocalizedString(
525-
"The site at this address is not a WordPress site. For us to connect to it, the site must use WordPress.",
526-
comment: "Error message shown a URL does not point to an existing site.")
527-
self.displayError(message: msg, moveVoiceOverFocus: true)
528-
541+
if let message = errorMessage {
542+
self.displayError(message: message, moveVoiceOverFocus: true)
529543
} else {
530544
self.displayError(error as NSError, sourceTag: self.sourceTag)
531545
}

0 commit comments

Comments
 (0)