Skip to content

Commit b490ec6

Browse files
committed
Avoid parsing an http body error if response is not from Ably.
1 parent 39da0cf commit b490ec6

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Source/ARTRest.m

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#import "ARTRest+Private.h"
2-
32
#import "ARTChannel+Private.h"
43
#import "ARTRestChannels+Private.h"
54
#import "ARTDataQuery+Private.h"
@@ -335,6 +334,16 @@ - (NSString *)agentIdentifierWithWrapperSDKAgents:(nullable NSDictionary<NSStrin
335334
return [ARTClientInformation agentIdentifierWithAdditionalAgents:additionalAgents];
336335
}
337336

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+
338347
/**
339348
originalRequestId is used only for fallback requests. It should never be used to execute request by yourself, it's passed from within below method.
340349
*/
@@ -413,10 +422,14 @@ - (NSString *)agentIdentifierWithWrapperSDKAgents:(nullable NSDictionary<NSStrin
413422
if (response.statusCode >= 400) {
414423
if (data) {
415424
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]]) {
420433
ARTLogDebug(self.logger, @"RS:%p retry request %@", self, request);
421434
// Make a single attempt to reissue the token and resend the request
422435
if (self->_tokenErrorRetries < 1) {

0 commit comments

Comments
 (0)