Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _None._

_None._

### New Features
- New tracking event for XMLRPC related failure. by @selanthiraiyan [#701]

_None._

Expand Down
2 changes: 1 addition & 1 deletion WordPressAuthenticator.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Pod::Spec.new do |s|
s.name = 'WordPressAuthenticator'
s.version = '4.1.1'
s.version = '4.2.0-beta.1'

s.summary = 'WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps.'
s.description = <<-DESC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ public class AuthenticatorAnalyticsTracker {
case loginWithAccountPassword = "login_with_password"
}

public enum Failure: String {
/// Failure to guess XMLRPC URL
///
case loginFailedToGuessXMLRPC = "login_failed_to_guess_xmlrpc_url"
}

/// Shared Instance.
///
public static var shared: AuthenticatorAnalyticsTracker = {
Expand Down Expand Up @@ -354,6 +360,12 @@ public class AuthenticatorAnalyticsTracker {
track(event(click: click))
}

/// Track a predefined failure enum.
///
public func track(failure: Failure) {
track(failure: failure.rawValue)
}

/// Track a failure.
///
public func track(failure: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,9 @@ private extension SiteAddressViewController {
// It's not guaranteed to be included in the error object depending on the error.
DDLogInfo("Error attempting to connect to site address: \(self.loginFields.siteAddress)")
DDLogError(error.localizedDescription)
// TODO: - Tracks.
// WordPressAuthenticator.track(.loginFailedToGuessXMLRPC, error: error)
// WordPressAuthenticator.track(.loginFailed, error: error)

self.tracker.track(failure: .loginFailedToGuessXMLRPC)

self.configureViewLoading(false)

guard self.isSiteDiscovery == false else {
Expand All @@ -505,27 +505,41 @@ private extension SiteAddressViewController {

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

let errorMessage: String? = {
if let xmlrpcValidatorError = err as? WordPressOrgXMLRPCValidatorError {
return xmlrpcValidatorError.localizedDescription
} else if (err.domain == NSURLErrorDomain && err.code == NSURLErrorCannotFindHost) ||
(err.domain == NSURLErrorDomain && err.code == NSURLErrorNetworkConnectionLost) {
// NSURLErrorNetworkConnectionLost can be returned when an invalid URL is entered.
let msg = NSLocalizedString(
"The site at this address is not a WordPress site. For us to connect to it, the site must use WordPress.",
comment: "Error message shown a URL does not point to an existing site.")
return msg
} else {
return nil
}
}()

/// Check if the host app wants to provide custom UI to handle the error.
/// If it does, insert the custom UI provided by the host app and exit early
if self.authenticationDelegate.shouldHandleError(err) {

// Send the error to the host app
self.authenticationDelegate.handleError(err) { customUI in
self.pushCustomUI(customUI)
}

// Track error message as failure
if let message = errorMessage {
self.tracker.track(failure: message)
}

// Return as the error has been handled by the host app.
return
}

if let xmlrpcValidatorError = err as? WordPressOrgXMLRPCValidatorError {
self.displayError(message: xmlrpcValidatorError.localizedDescription, moveVoiceOverFocus: true)

} else if (err.domain == NSURLErrorDomain && err.code == NSURLErrorCannotFindHost) ||
(err.domain == NSURLErrorDomain && err.code == NSURLErrorNetworkConnectionLost) {
// NSURLErrorNetworkConnectionLost can be returned when an invalid URL is entered.
let msg = NSLocalizedString(
"The site at this address is not a WordPress site. For us to connect to it, the site must use WordPress.",
comment: "Error message shown a URL does not point to an existing site.")
self.displayError(message: msg, moveVoiceOverFocus: true)

if let message = errorMessage {
self.displayError(message: message, moveVoiceOverFocus: true)
} else {
self.displayError(error as NSError, sourceTag: self.sourceTag)
}
Expand Down