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

Conversation

@ctarda
Copy link
Contributor

@ctarda ctarda commented Nov 27, 2020

Closes #530
Ref: p91TBi-3Rn-p2

Changes

  • Added two new methods to WPAuthenticatorDelegate to allow host apps to decide if they want to handle errors.
  • Bumped the podspec
  • Extracted a private method in SiteAddressViewController to execute the insertion of custom UI

How to test

///
func shouldPresentLoginEpilogue(isJetpackLogin: Bool) -> Bool

/// Indicates the Host app wants to handle and display a given error.
Copy link
Contributor Author

@ctarda ctarda Nov 27, 2020

Choose a reason for hiding this comment

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

These two methods would be new. This would break WordPress, but the fix is simple: for host apps that are good with WPAuthenticator's error handling, shoudlDisplayError would just return false, and handleError would do nothing

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the info! After this is merged, I'll create a WP PR to address this.

}
}

override func displayRemoteError(_ error: Error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might not be necessary. In fact, I would argue that it would be good to avoid doing it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sorry, but I'm confused by this. It appears you added this override method to implement your error handling. Why do you not agree with what you just did? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, that was terrible wording on my side. Let me rephrase my comment:

"I am not 100% sure that this is absolutely necessary. So far I have not seen this override being used in any of the tests I have run using WooCommerce. That does not mean it won't happen as I continue testing. I would prefer if, eventually, we noticed that overriding this method is actually unnecessary and we could get rid of the override"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I just found a test case for WooCommerce where these overrides are necessary: a Pressable store with Jetpack installed but not activated

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh! OK, that makes more sense. 😄 Thank you sir!


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

if self.authenticationDelegate.shouldDisplayError(err) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what actually inserts the custom UI for the case when the url provided for login with site address is not a WordPress site. This code would use some cleanup, but I hope it helps illustrate how this solution would work


/// Signals the Host app that there is an error that needs to be handled.
///
func handleError(_ error: Error, onCompletion: @escaping (WordPressAuthenticatorResult) -> Void)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The parameter in the completion block might just be of type UIViewController. After all, host apps would only call this method if they actually want to inject a custom error UI

@ctarda ctarda self-assigned this Dec 1, 2020
@ctarda ctarda added the enhancement New feature or request label Dec 1, 2020
@ctarda ctarda marked this pull request as ready for review December 1, 2020 08:33
}

override func displayRemoteError(_ error: Error) {
guard authenticationDelegate.shouldHandleError(error) == true else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this just be guard authenticationDelegate.shouldHandleError(error) else {?

Copy link
Contributor

Choose a reason for hiding this comment

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

iirc, this is part of Woo's coding style. I could be wrong though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's probably muscle memory. I'll update it

Copy link
Contributor

@mindgraffiti mindgraffiti left a comment

Choose a reason for hiding this comment

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

This approach seems reasonable to me, though I am curious about your answer to Stephenie's question (about why you don't like overriding the displayRemoteError) 😀

@ctarda
Copy link
Contributor Author

ctarda commented Dec 2, 2020

Thanks for the review @mindgraffiti @ScoutHarris

I bumped the podspec, updated the guard clause and hopefully clarified my comment about the override.

I'll merge when CI is ✅

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow host apps to handle errors

4 participants