diff --git a/Shared/Generated/Strings.swift b/Shared/Generated/Strings.swift index 9a6d04d4..b6b5fb87 100644 --- a/Shared/Generated/Strings.swift +++ b/Shared/Generated/Strings.swift @@ -354,6 +354,8 @@ internal enum L10n { internal static var system: String { return L10n.tr("Localizable", "system") } /// Tags internal static var tags: String { return L10n.tr("Localizable", "tags") } + /// Too Many Redirects + internal static var tooManyRedirects: String { return L10n.tr("Localizable", "tooManyRedirects") } /// Try again internal static var tryAgain: String { return L10n.tr("Localizable", "tryAgain") } /// TV Shows diff --git a/Shared/ViewModels/ConnectToServerViewModel.swift b/Shared/ViewModels/ConnectToServerViewModel.swift index aa86ed37..426b5a37 100644 --- a/Shared/ViewModels/ConnectToServerViewModel.swift +++ b/Shared/ViewModels/ConnectToServerViewModel.swift @@ -44,7 +44,8 @@ final class ConnectToServerViewModel: ViewModel { return message } - func connectToServer(uri: String) { + func connectToServer(uri: String, redirectCount: Int = 0) { + #if targetEnvironment(simulator) var uri = uri if uri == "localhost" { @@ -63,6 +64,27 @@ final class ConnectToServerViewModel: ViewModel { case .finished: () case let .failure(error): switch error { + case is ErrorResponse: + let errorResponse = error as! ErrorResponse + switch errorResponse { + case let .error(_, _, response, _): + // a url in the response is the result if a redirect + if let newURL = response?.url { + if redirectCount > 2 { + self.handleAPIRequestError(displayMessage: L10n.tooManyRedirects, + logLevel: .critical, + tag: "connectToServer", + completion: completion) + } else { + self + .connectToServer(uri: newURL.absoluteString + .removeRegexMatches(pattern: "/web/index.html"), + redirectCount: redirectCount + 1) + } + } else { + self.handleAPIRequestError(completion: completion) + } + } case is SwiftfinStore.Errors: let swiftfinError = error as! SwiftfinStore.Errors switch swiftfinError { diff --git a/Translations/en.lproj/Localizable.strings b/Translations/en.lproj/Localizable.strings index cc09b41e..a1457c89 100644 Binary files a/Translations/en.lproj/Localizable.strings and b/Translations/en.lproj/Localizable.strings differ