Skip to content

Commit

Permalink
fix(AWSLocation): Fixing clock skew retries (#5491)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaland authored Jan 10, 2025
1 parent e00fa50 commit 95a2a45
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integ-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
- AWSKinesisVideoSignaling
- AWSLambda
- AWSLex
- AWSLocation
- AWSPinpoint
- AWSPolly
- AWSRekognition
Expand Down
41 changes: 24 additions & 17 deletions AWSLocation/AWSLocationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,34 @@ - (id)responseObjectForResponse:(NSHTTPURLResponse *)response
data:data
error:error];
if (!*error && [responseObject isKindOfClass:[NSDictionary class]]) {
NSString *errorTypeString = [[response allHeaderFields] objectForKey:@"x-amzn-ErrorType"];
if (!error) {
return responseObject;
}

NSString *errorTypeString = [[response allHeaderFields] objectForKey:@"x-amzn-ErrorType"];
NSString *errorTypeHeader = [[errorTypeString componentsSeparatedByString:@":"] firstObject];

if ([errorTypeString length] > 0 && errorTypeHeader) {
if (errorCodeDictionary[errorTypeHeader]) {
if (error) {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey : [responseObject objectForKey:@"message"]?[responseObject objectForKey:@"message"]:[NSNull null], NSLocalizedFailureReasonErrorKey: errorTypeString};
*error = [NSError errorWithDomain:AWSLocationErrorDomain
code:[[errorCodeDictionary objectForKey:errorTypeHeader] integerValue]
userInfo:userInfo];
}
return responseObject;
} else if (errorTypeHeader) {
if (error) {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey : [responseObject objectForKey:@"message"]?[responseObject objectForKey:@"message"]:[NSNull null], NSLocalizedFailureReasonErrorKey: errorTypeString};
*error = [NSError errorWithDomain:AWSLocationErrorDomain
code:AWSLocationErrorUnknown
userInfo:userInfo];
}
return responseObject;
NSString *errorDomain = nil;
NSNumber *errorCode = nil;

if (errorCodeDictionary[errorTypeHeader]) { // First, check if it's a Location error
errorDomain = AWSLocationErrorDomain;
errorCode = errorCodeDictionary[errorTypeHeader];
} else if ([[AWSService errorCodeDictionary] objectForKey:errorTypeHeader]) { // Then, check if it's a Service error
errorDomain = AWSServiceErrorDomain;
errorCode = [[AWSService errorCodeDictionary] objectForKey:errorTypeHeader];
} else { // Finally, fallback to an unknown location error
errorDomain = AWSLocationErrorDomain;
errorCode = [[NSNumber alloc] initWithInt:AWSLocationErrorUnknown];
}

NSDictionary *userInfo = @{NSLocalizedDescriptionKey : [responseObject objectForKey:@"message"]?[responseObject objectForKey:@"message"]:[NSNull null], NSLocalizedFailureReasonErrorKey: errorTypeString};
*error = [NSError errorWithDomain:errorDomain
code:[errorCode integerValue]
userInfo:userInfo];

return responseObject;
}
}

Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Unreleased

-Features for next release
### Bug Fixes
- **AWSLocation**
- Fixing clock skew retries (#5491)

## 2.39.0

Expand Down

0 comments on commit 95a2a45

Please sign in to comment.