@@ -140,6 +140,17 @@ final class SiteAddressViewController: LoginViewController {
140140 }
141141 }
142142
143+ override func displayRemoteError( _ error: Error ) {
144+ guard authenticationDelegate. shouldHandleError ( error) else {
145+ super. displayRemoteError ( error)
146+ return
147+ }
148+
149+ authenticationDelegate. handleError ( error) { customUI in
150+ self . navigationController? . pushViewController ( customUI, animated: true )
151+ }
152+ }
153+
143154 /// Reload the tableview and show errors, if any.
144155 ///
145156 override func displayError( message: String , moveVoiceOverFocus: Bool = false ) {
@@ -351,6 +362,19 @@ private extension SiteAddressViewController {
351362 }
352363 }
353364
365+ /// Push a custom view controller, provided by a host app, to the navigation stack
366+ func pushCustomUI( _ customUI: UIViewController ) {
367+ /// Assign the help button of the newly injected UI to the same help button we are currently displaying
368+ /// We are making a somewhat big assumption here: the chrome of the new UI we insert would look like the UI
369+ /// WPAuthenticator is already displaying. Which is risky, but also kind of makes sense, considering
370+ /// we are also pushing that injected UI to the current navigation controller.
371+ if WordPressAuthenticator . shared. delegate? . supportActionEnabled == true {
372+ customUI. navigationItem. rightBarButtonItems = self . navigationItem. rightBarButtonItems
373+ }
374+
375+ self . navigationController? . pushViewController ( customUI, animated: true )
376+ }
377+
354378 // MARK: - Private Constants
355379
356380 /// Rows listed in the order they were created.
@@ -419,6 +443,16 @@ private extension SiteAddressViewController {
419443
420444 let err = self . originalErrorOrError ( error: error as NSError )
421445
446+ /// Check if the host app wants to provide custom UI to handle the error.
447+ /// If it does, insert the custom UI provided by the host app and exit early
448+ if self . authenticationDelegate. shouldHandleError ( err) {
449+ self . authenticationDelegate. handleError ( err) { customUI in
450+ self . pushCustomUI ( customUI)
451+ }
452+
453+ return
454+ }
455+
422456 if let xmlrpcValidatorError = err as? WordPressOrgXMLRPCValidatorError {
423457 self . displayError ( message: xmlrpcValidatorError. localizedDescription, moveVoiceOverFocus: true )
424458
@@ -480,14 +514,7 @@ private extension SiteAddressViewController {
480514
481515 self . showWPUsernamePassword ( )
482516 case let . injectViewController( customUI) :
483- /// Assign the help button of the newly injected UI to the same help button we are currently displaying
484- /// We are making a somewhat big assumption here: the chrome of the new UI we insert would look like the UI
485- /// WPAuthenticator is already displaying. Which is risky, but also kind of makes sense, considering
486- /// we are also pushing that injected UI to the current navigation controller.
487- if WordPressAuthenticator . shared. delegate? . supportActionEnabled == true {
488- customUI. navigationItem. rightBarButtonItems = self . navigationItem. rightBarButtonItems
489- }
490- self . navigationController? . pushViewController ( customUI, animated: true )
517+ self . pushCustomUI ( customUI)
491518 }
492519 } )
493520 }
0 commit comments