fix invalid auth token handling with onion request

pull/246/head
Ryan ZHAO 5 years ago
parent 660146735d
commit 8d44115195

@ -156,7 +156,7 @@ final class JoinPublicChatVC : BaseVC, UIPageViewControllerDataSource, UIPageVie
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
var title = "Couldn't Join"
var message = ""
if case HTTP.Error.httpRequestFailed(let statusCode, _) = error, statusCode == 401 || statusCode == 403 {
if case OnionRequestAPI.Error.httpRequestFailedAtTargetSnode(statusCode: let statusCode, json: _) = error, statusCode == 401 || statusCode == 403 {
title = "Unauthorized"
message = "Please ask the open group operator to add you to the group."
}

@ -187,17 +187,3 @@ public class DotNetAPI : NSObject {
}
}
}
// MARK: Error Handling
internal extension Promise {
internal func handlingInvalidAuthTokenIfNeeded(for server: String) -> Promise<T> {
return recover2 { error -> Promise<T> in
if case HTTP.Error.httpRequestFailed(let statusCode, _) = error, statusCode == 401 || statusCode == 403 {
print("[Loki] Auth token for: \(server) expired; dropping it.")
DotNetAPI.removeAuthToken(for: server)
}
throw error
}
}
}

@ -26,7 +26,7 @@ public enum OnionRequestAPI {
}
// MARK: Error
internal enum Error : LocalizedError {
public enum Error : LocalizedError {
case httpRequestFailedAtTargetSnode(statusCode: UInt, json: JSON)
case insufficientSnodes
case invalidURL
@ -35,7 +35,7 @@ public enum OnionRequestAPI {
case snodePublicKeySetMissing
case unsupportedSnodeVersion(String)
internal var errorDescription: String? {
public var errorDescription: String? {
switch self {
case .httpRequestFailedAtTargetSnode(let statusCode): return "HTTP request failed at target snode with status code: \(statusCode)."
case .insufficientSnodes: return "Couldn't find enough snodes to build a path."

@ -523,3 +523,17 @@ public final class PublicChatAPI : DotNetAPI {
return moderators[server]?[channel]?.contains(hexEncodedPublicString) ?? false
}
}
// MARK: Error Handling
internal extension Promise {
internal func handlingInvalidAuthTokenIfNeeded(for server: String) -> Promise<T> {
return recover2 { error -> Promise<T> in
if case OnionRequestAPI.Error.httpRequestFailedAtTargetSnode(let statusCode, _) = error, statusCode == 401 || statusCode == 403 {
print("[Loki] Auth token for: \(server) expired; dropping it.")
PublicChatAPI.removeAuthToken(for: server)
}
throw error
}
}
}

Loading…
Cancel
Save