Skip to content
Open
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
4 changes: 2 additions & 2 deletions ios/Demo-iOS/Gutenberg.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Automattic/wordpress-rs";
requirement = {
kind = exactVersion;
version = 0.6.0;
kind = revision;
revision = d70c99e1ff38772353bd8f6a81879320990a560e;
Comment on lines +576 to +577

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to use a wordpress-rs commit hash for the Demo app or do we need to await a tag?

};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 2 additions & 24 deletions ios/Demo-iOS/Sources/Views/SitePreparationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class SitePreparationViewModel {
try await self.loadPostTypes()
let newConfiguration = try await self.loadConfiguration(for: account)
self.editorConfiguration = Self.applyDemoAppDefaults(to: newConfiguration)
} catch let error where Self.isUnreachableSiteError(error) {
} catch let error as WpApiError where error.isSiteUnreachable {
throw AppError(errorDescription: "Could not connect to Local WordPress at localhost:8888.\n\nThe wp-env server may not be running. Start it with 'make wp-env-start'.")
}
case .account(let account):
Expand Down Expand Up @@ -303,7 +303,7 @@ class SitePreparationViewModel {
try await self.loadPostTypes()
let newConfiguration = try await self.loadConfiguration(for: account)
self.editorConfiguration = Self.applyDemoAppDefaults(to: newConfiguration)
} catch let error where Self.isNetworkError(error) {
} catch let error as WpApiError where error.isDeviceOffline {
self.postTypes = [.post, .page]
let fallback = Self.buildOfflineConfiguration(for: account)
self.editorConfiguration = Self.applyDemoAppDefaults(to: fallback)
Expand All @@ -322,28 +322,6 @@ class SitePreparationViewModel {
.build()
}

/// Whether the site could not be reached at all — the host did not resolve
/// or refused the connection.
///
/// wordpress-rs intercepts the underlying `URLError` and rewraps it as a
/// `WpApiError`, so matching `URLError` alone never fires for a site that
/// is simply not running.
private static func isUnreachableSiteError(_ error: Error) -> Bool {
if let wpError = error as? WpApiError,
case .RequestExecutionFailed(_, _, .nonExistentSiteError, _, _) = wpError {
return true
}
return error is URLError
}

private static func isNetworkError(_ error: Error) -> Bool {
if let wpError = error as? WpApiError,
case .RequestExecutionFailed(_, _, .deviceIsOfflineError, _, _) = wpError {
return true
}
return error is URLError
}

private static func buildOfflineConfiguration(for account: Account) -> EditorConfiguration {
EditorConfigurationBuilder(
postType: .post,
Expand Down
Loading