From dc2ecc787b65c1b87de9cb841989df8eee032e24 Mon Sep 17 00:00:00 2001 From: Aadharsh Pannirselvam <19518661+oddharsh@users.noreply.github.com> Date: Thu, 3 Sep 2026 13:51:25 -0400 Subject: [PATCH] Surface HTTP errors from GSA auth instead of a plist parse failure gsa.apple.com/grandslam/GsService2 occasionally responds to the auth request with a plain HTTP error page (e.g. 503 Service Temporarily Unavailable) instead of a plist body. sendAuthenticationRequestWithParameters: fed that HTML straight into NSPropertyListSerialization, which failed with "Encountered unknown tag html on line 1" / kCFPropertyListOldStyleParsingError - a confusing, low-level error that gives no hint the real issue is a transient server error on Apple's end. Check the response status code before parsing and return a clear, actionable error when it's non-2xx. --- AltSign/Apple API/ALTAppleAPI+Authentication.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/AltSign/Apple API/ALTAppleAPI+Authentication.m b/AltSign/Apple API/ALTAppleAPI+Authentication.m index 7a459756..6cf3b684 100644 --- a/AltSign/Apple API/ALTAppleAPI+Authentication.m +++ b/AltSign/Apple API/ALTAppleAPI+Authentication.m @@ -713,6 +713,21 @@ - (void)sendAuthenticationRequestWithParameters:(NSDictionary *)requestDictionar return; } + // Apple's GSA endpoint occasionally responds to this request with a plain + // HTTP error page (e.g. 503 Service Temporarily Unavailable) instead of a + // plist body. Parsing that HTML as a plist below fails with a confusing, + // low-level "unknown tag html" / kCFPropertyListOldStyleParsingError, which + // gives no indication the actual problem is a transient server error. Check + // the status code first so that case gets a clear, actionable message. + NSHTTPURLResponse *httpResponse = [response isKindOfClass:[NSHTTPURLResponse class]] ? (NSHTTPURLResponse *)response : nil; + if (httpResponse != nil && (httpResponse.statusCode < 200 || httpResponse.statusCode >= 300)) + { + NSString *localizedDescription = [NSString stringWithFormat:@"Apple's servers returned an error while authenticating (HTTP %@). Please try again later.", @(httpResponse.statusCode)]; + NSError *error = [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorUnknown userInfo:@{NSLocalizedDescriptionKey: localizedDescription}]; + completionHandler(nil, error); + return; + } + NSError *parseError = nil; NSDictionary *responseDictionary = [NSPropertyListSerialization propertyListWithData:data options:0 format:nil error:&parseError];