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

Commit cd55dfe

Browse files
authored
Merge pull request #48 from wordpress-mobile/fix/show_meaningful_error_when_xmlrpc_broken
Show meaningful error when xmlrpc broken
2 parents e7bbb98 + 5680fb3 commit cd55dfe

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ PODS:
2727
- OHHTTPStubs/Swift (6.1.0):
2828
- OHHTTPStubs/Default
2929
- UIDeviceIdentifier (0.5.0)
30-
- WordPressKit (1.4.3-beta.1):
30+
- WordPressKit (1.4.3-beta.2):
3131
- Alamofire (~> 4.7.3)
3232
- CocoaLumberjack (= 3.4.2)
3333
- NSObject-SafeExpectations (= 0.0.3)
@@ -70,7 +70,7 @@ SPEC CHECKSUMS:
7070
OCMock: ebe9ee1dca7fbed0ff9193ac0b3e2d8862ea56f6
7171
OHHTTPStubs: 1e21c7d2c084b8153fc53d48400d8919d2d432d0
7272
UIDeviceIdentifier: a959a6d4f51036b4180dd31fb26483a820f1cc46
73-
WordPressKit: 07501ceb3e9cbebbbe64ad02dcaff44807406450
73+
WordPressKit: 7b6fec9b382c0a9f553b82a4eb133ad685b9f879
7474
WordPressShared: 7ef0253d54989b195e020a74100a8500be0a4315
7575
wpxmlrpc: bfc572f62ce7ee897f6f38b098d2ba08732ecef4
7676

WordPressKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressKit"
3-
s.version = "1.4.3-beta.1"
3+
s.version = "1.4.3-beta.2"
44

55
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
66

WordPressKit/WordPressOrgXMLRPCValidator.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import CocoaLumberjack
1111
case forbidden = 403 // Server returned a 403 error while reading xmlrpc file
1212
case blocked = 405 // Server returned a 405 error while reading xmlrpc file
1313
case invalid // Doesn't look to be valid XMLRPC Endpoint.
14+
case xmlrpc_missing // site contains RSD link but XML-RPC information is missing
1415

1516
public var localizedDescription: String {
1617
switch (self) {
@@ -25,11 +26,13 @@ import CocoaLumberjack
2526
case .mobilePluginRedirectedError:
2627
return NSLocalizedString("You seem to have installed a mobile plugin from DudaMobile which is preventing the app to connect to your blog", comment: "")
2728
case .invalid:
28-
return NSLocalizedString("We're sure this is a great site - but it's not a WordPress site, so you can't connect to it with this app.", comment: "Error message shown a URL points to a valid site but not a WordPress site.")
29+
return NSLocalizedString("Couldn't connect to the WordPress site. There is no valid WordPress site at this address. Check the site address (URL) you entered.", comment: "Error message shown a URL points to a valid site but not a WordPress site.")
2930
case .blocked:
3031
return NSLocalizedString("Couldn't connect. Your host is blocking POST requests, and the app needs that in order to communicate with your site. Contact your host to solve this problem.", comment: "Message to show to user when he tries to add a self-hosted site but the host returned a 405 error, meaning that the host is blocking POST requests on /xmlrpc.php file.")
3132
case .forbidden:
3233
return NSLocalizedString("Couldn't connect. We received a 403 error when trying to access your site XMLRPC endpoint. The app needs that in order to communicate with your site. Contact your host to solve this problem.", comment: "Message to show to user when he tries to add a self-hosted site but the host returned a 403 error, meaning that the access to the /xmlrpc.php file is forbidden.")
34+
case .xmlrpc_missing:
35+
return NSLocalizedString("Couldn't connect. Required XML-RPC methods are missing on the server.", comment: "Message to show to user when he tries to add a self-hosted site with RSD link present, but xmlrpc is missing.")
3336
}
3437
}
3538
}
@@ -192,6 +195,7 @@ open class WordPressOrgXMLRPCValidator: NSObject {
192195
redirectCount: Int = 0,
193196
success: @escaping (_ xmlrpcURL: URL) -> (),
194197
failure: @escaping (_ error: NSError) -> ()) {
198+
195199
guard redirectCount < redirectLimit else {
196200
let error = NSError(domain: URLError.errorDomain,
197201
code: URLError.httpTooManyRedirects.rawValue,
@@ -247,6 +251,8 @@ open class WordPressOrgXMLRPCValidator: NSObject {
247251
success: @escaping (_ xmlrpcURL: URL) -> (),
248252
failure: @escaping (_ error: NSError) -> ()) {
249253
DDLogInfo("Fetch the original url and look for the RSD link by using RegExp")
254+
255+
var isWpSite = false
250256
let session = URLSession(configuration: URLSessionConfiguration.ephemeral)
251257
let dataTask = session.dataTask(with: htmlURL, completionHandler: { (data, response, error) in
252258
if let error = error {
@@ -261,6 +267,9 @@ open class WordPressOrgXMLRPCValidator: NSObject {
261267
return
262268
}
263269

270+
// If the site contains RSD link, it is WP.org site
271+
isWpSite = true
272+
264273
// Try removing "?rsd" from the url, it should point to the XML-RPC endpoint
265274
let xmlrpc = rsdURL.replacingOccurrences(of: "?rsd", with: "")
266275
if xmlrpc != rsdURL {
@@ -273,7 +282,9 @@ open class WordPressOrgXMLRPCValidator: NSObject {
273282
if error.code == 403 || error.code == 405, let xmlrpcValidatorError = error as? WordPressOrgXMLRPCValidatorError {
274283
failure(xmlrpcValidatorError as NSError)
275284
} else {
276-
failure(WordPressOrgXMLRPCValidatorError.invalid as NSError)
285+
let validatorError = isWpSite ? WordPressOrgXMLRPCValidatorError.xmlrpc_missing :
286+
WordPressOrgXMLRPCValidatorError.invalid
287+
failure(validatorError as NSError)
277288
}
278289
})
279290
} else {

0 commit comments

Comments
 (0)