|
1 | 1 | #import "ARTRest+Private.h" |
2 | | - |
3 | 2 | #import "ARTChannel+Private.h" |
4 | 3 | #import "ARTRestChannels+Private.h" |
5 | 4 | #import "ARTDataQuery+Private.h" |
@@ -335,6 +334,16 @@ - (NSString *)agentIdentifierWithWrapperSDKAgents:(nullable NSDictionary<NSStrin |
335 | 334 | return [ARTClientInformation agentIdentifierWithAdditionalAgents:additionalAgents]; |
336 | 335 | } |
337 | 336 |
|
| 337 | +// Checks if the response contains any Ably header |
| 338 | +- (BOOL)isAblyResponse:(NSHTTPURLResponse *)response { |
| 339 | + for (NSString* key in response.allHeaderFields) { |
| 340 | + if ([key.lowercaseString containsString:@"-ably"]) { |
| 341 | + return true; |
| 342 | + } |
| 343 | + } |
| 344 | + return false; |
| 345 | +} |
| 346 | + |
338 | 347 | /** |
339 | 348 | originalRequestId is used only for fallback requests. It should never be used to execute request by yourself, it's passed from within below method. |
340 | 349 | */ |
@@ -413,10 +422,14 @@ - (NSString *)agentIdentifierWithWrapperSDKAgents:(nullable NSDictionary<NSStrin |
413 | 422 | if (response.statusCode >= 400) { |
414 | 423 | if (data) { |
415 | 424 | NSError *decodeError = nil; |
416 | | - ARTErrorInfo *dataError = [self->_encoders[response.MIMEType] decodeErrorInfo:data |
417 | | - statusCode:response.statusCode |
418 | | - error:&decodeError]; |
419 | | - if ([self shouldRenewToken:&dataError] && [request isKindOfClass:[NSMutableURLRequest class]]) { |
| 425 | + ARTErrorInfo *dataError = nil; |
| 426 | + id<ARTEncoder> encoder = self->_encoders[response.MIMEType]; |
| 427 | + |
| 428 | + if (encoder && [self isAblyResponse:response]) { |
| 429 | + dataError = [encoder decodeErrorInfo:data statusCode:response.statusCode error:&decodeError]; |
| 430 | + } |
| 431 | + |
| 432 | + if (dataError && [self shouldRenewToken:&dataError] && [request isKindOfClass:[NSMutableURLRequest class]]) { |
420 | 433 | ARTLogDebug(self.logger, @"RS:%p retry request %@", self, request); |
421 | 434 | // Make a single attempt to reissue the token and resend the request |
422 | 435 | if (self->_tokenErrorRetries < 1) { |
|
0 commit comments