Merge pull request #300 from LePips/support-redirects
Support Redirects
This commit is contained in:
commit
28f23a439a
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue