Reputation: 728
I am using the exported API Gateway IOS SDK. The API was originally imported to the API Gateway via Swagger as a template, but since modified with the AWS portal to map back to the response model and class within the IOS SDK. All 200 requests are returned with no issue. I am using pod 'AWSAPIGateway', '= 2.4.1'
The issue i am having is nothing else other then 200 response is handled and/or received by the IOS SDK. I know it is sent because Cloudwatch shows the correct mapping, but nothing is returned in the IOS App.
At first i thought maybe i was conflicting with the API Gateway's own response codes so i switched to 403 which wasn't on it list. But that didn't work. I am also not getting 500 response errors.
Here is the calling function:
client.apiRequestPut(apiRequestVar).continueWithSuccessBlock {
(task: AWSTask!) -> AnyObject! in
print(task)
if ((task.error) != nil) {
print(task.error)
return nil;
}
if( (task.result != nil)) {
print(task.result)
}
}
return nil
}
And the AWS SDK Generated Client Function:
- (AWSTask *)apiRequestPut:(APINewRequest *)body {
NSDictionary *headerParameters = @{
@"Content-Type": @"application/json",
@"Accept": @"application/json",
};
NSDictionary *queryParameters = @{
};
NSDictionary *pathParameters = @{
};
return [self invokeHTTPRequest:@"PUT"
URLString:@"/requestVariable"
pathParameters:pathParameters
queryParameters:queryParameters
headerParameters:headerParameters
body:body
responseClass:[APIModel class]];
}
}
Here is the Error Model:
@implementation APIErrorModel
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"success": @"success",
@"theFunction": @"theFunction",
@"action": @"action",
@"timeStamp": @"timeStamp",
@"error": @"error",
@"data": @"data"
};
}
+ (NSValueTransformer *)timeStampJSONTransformer {
return [AWSMTLValueTransformer reversibleTransformerWithForwardBlock:^id(NSString *dateString) {
return [NSDate aws_dateFromString:dateString format:AWSDateISO8601DateFormat1];
} reverseBlock:^id(NSDate *date) {
return [date aws_stringValue:AWSDateISO8601DateFormat1];
}];
}
Here is the mapping in the API Gateway for 400 response code:
#set($inputRoot = $input.path('$'))
{
"success" : $input.json('$.success'),
"theFunction" : "foo",
"action" : "foo",
"timeStamp" : "foo",
"error" : "foo",
"data" : $input.json('$.message')
}
Here is the resulting Cloudwatch log entry:
Endpoint response body before transformations:
{
"success": false,
"message": "{\"message\":\"The conditional request failed\",\"code\":\"ConditionalCheckFailedException\",\"time\":\"2016-05- 12T20:16:03.165Z\",\"statusCode\":400,\"retryable\":false,\"retryDelay\":0} "
}
Endpoint response headers: {content-length=217, Connection=keep-alive, content-type=application/json; charset=utf-8, cache-control=no-cache, Date=Thu, 12 May 2016 20:16:03 GMT
}
Method response body after transformations:
{
"success": false,
"theFunction": "foo",
"action": "foo",
"timeStamp": "foo",
"error": "foo",
"data": "{\"message\":\"The conditional request failed\",\"code\":\"ConditionalCheckFailedException\",\"time\":\"2016-05- 12T20:16:03.165Z\",\"statusCode\":400,\"retryable\":false,\"retryDelay\":0} "
}
Method response headers: {Content-Type=application/json}
Successfully completed execution
Method completed with status: 400
But then i get nothing received back in the iOS app?
Any help to what i am missing would be much appreciated!
Upvotes: 0
Views: 527
Reputation: 3759
- continueWithSuccessBlock:
is used when you want to extract only the result
from the task object. The task
object in - continueWithSuccessBlock:
always has the nil
error
property. If you want to receive errors, you need to use - continueWithBlock:
instead.
See the Bolts documentation for more details.
Upvotes: 1