From 1de49b80e9a6f757698f73e87546d076c5b30fdc Mon Sep 17 00:00:00 2001 From: Eric Bariaux <375613+ebariaux@users.noreply.github.com> Date: Thu, 10 Apr 2025 17:14:59 +0200 Subject: [PATCH] Handle fact HttpApiManager initializer can now throw and review more specific error message displayed to user --- .../UI/WizardDomainViewController.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/GenericApp/GenericApp/UI/WizardDomainViewController.swift b/GenericApp/GenericApp/UI/WizardDomainViewController.swift index 671630c..61f207c 100644 --- a/GenericApp/GenericApp/UI/WizardDomainViewController.swift +++ b/GenericApp/GenericApp/UI/WizardDomainViewController.swift @@ -91,18 +91,18 @@ extension WizardDomainViewController: UITextFieldDelegate { } fileprivate func requestAppConfig(_ domain: String) { - configManager = ConfigManager(apiManagerFactory: { url in - HttpApiManager(baseUrl: url) - }) - async { do { + configManager = ConfigManager(apiManagerFactory: { url in + try HttpApiManager(baseUrl: url) + }) + let state = try await configManager!.setDomain(domain: domain) print("State \(state)") switch state { case .selectDomain: // Something wrong, we just set the domain - let alertView = UIAlertController(title: "Error", message: "Error occurred getting app config. Check your input and try again", preferredStyle: .alert) + let alertView = UIAlertController(title: "Error", message: "Error occurred getting app config.\nCheck your input and try again.", preferredStyle: .alert) alertView.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) self.present(alertView, animated: true, completion: nil) @@ -113,8 +113,12 @@ extension WizardDomainViewController: UITextFieldDelegate { case.complete: self.performSegue(withIdentifier: Segues.goToWebView, sender: self) } + } catch ApiManagerError.invalidUrl { + let alertView = UIAlertController(title: "Error", message: "Invalid domain.\nCheck your input and try again.", preferredStyle: .alert) + alertView.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) + self.present(alertView, animated: true, completion: nil) } catch { - let alertView = UIAlertController(title: "Error", message: "Error occurred getting app config. Check your input and try again", preferredStyle: .alert) + let alertView = UIAlertController(title: "Error", message: "Error occurred getting app config.\nCheck your input and try again.", preferredStyle: .alert) alertView.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) self.present(alertView, animated: true, completion: nil) }