From 04d81ed9e4da0ba89b1be73a2209391f9d7c37b4 Mon Sep 17 00:00:00 2001 From: Oskar Figiel Date: Mon, 1 Nov 2021 17:30:39 +0100 Subject: [PATCH] Show a message when user is not authorized yet --- Xcodes/AppleAPI/Sources/AppleAPI/Client.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Xcodes/AppleAPI/Sources/AppleAPI/Client.swift b/Xcodes/AppleAPI/Sources/AppleAPI/Client.swift index a45d300..cb4ec68 100644 --- a/Xcodes/AppleAPI/Sources/AppleAPI/Client.swift +++ b/Xcodes/AppleAPI/Sources/AppleAPI/Client.swift @@ -148,7 +148,14 @@ public class Client { /// Use the olympus session endpoint to see if the existing session is still valid public func validateSession() -> AnyPublisher { return Current.network.dataTask(with: URLRequest.olympusSession) - .map(\.data) + .tryMap { result -> Data in + let httpResponse = result.response as! HTTPURLResponse + if httpResponse.statusCode == 401 { + throw AuthenticationError.notAuthorized + } + + return result.data + } .decode(type: AppleSession.self, decoder: JSONDecoder()) .tryMap { session in if session.provider == nil { @@ -189,6 +196,7 @@ public enum AuthenticationError: Swift.Error, LocalizedError, Equatable { case accountLocked(String) case badStatusCode(statusCode: Int, data: Data, response: HTTPURLResponse) case notDeveloperAppleId + case notAuthorized public var errorDescription: String? { switch self { @@ -217,6 +225,8 @@ public enum AuthenticationError: Swift.Error, LocalizedError, Equatable { return "Received an unexpected status code: \(statusCode). If you continue to have problems, please submit a bug report in the Help menu." case .notDeveloperAppleId: return "You are not registered as an Apple Developer. Please visit Apple Developer Registration. https://developer.apple.com/register/" + case .notAuthorized: + return "You are not authorized. Please Sign in with your Apple ID first." } } }