AWS API 网关导出 IOS SDK 无错误响应
AWS API Gateway exported IOS SDK no error response
我正在使用导出的 API 网关 IOS SDK。 API 最初作为模板通过 Swagger 导入到 API 网关,但后来使用 AWS 门户进行了修改以映射回 IOS 中的响应模型和 class开发工具包。所有 200 个请求都没有问题地返回。我正在使用 pod 'AWSAPIGateway', '= 2.4.1'
我遇到的问题是 IOS SDK 处理 and/or 收到的 200 响应。我知道它已发送,因为 Cloudwatch 显示了正确的映射,但 IOS 应用程序中没有返回任何内容。
起初我以为我可能与 API 网关自己的响应代码冲突,所以我切换到 403,它不在它的列表中。但这没有用。我也没有收到 500 个响应错误。
这里是调用函数:
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
}
以及 AWS SDK 生成的客户端函数:
- (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]];
}
}
这是错误模型:
@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];
}];
}
这是 API 网关中 400 响应代码的映射:
#set($inputRoot = $input.path('$'))
{
"success" : $input.json('$.success'),
"theFunction" : "foo",
"action" : "foo",
"timeStamp" : "foo",
"error" : "foo",
"data" : $input.json('$.message')
}
这是生成的 Cloudwatch 日志条目:
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
但是我在 iOS 应用程序中没有收到任何回复?
任何对我遗漏的帮助都将不胜感激!
当您只想从任务对象中提取 result
时,使用 - continueWithSuccessBlock:
。 - continueWithSuccessBlock:
中的 task
对象始终具有 nil
error
属性。如果你想接收错误,你需要使用 - continueWithBlock:
来代替。
有关详细信息,请参阅 Bolts 文档。
我正在使用导出的 API 网关 IOS SDK。 API 最初作为模板通过 Swagger 导入到 API 网关,但后来使用 AWS 门户进行了修改以映射回 IOS 中的响应模型和 class开发工具包。所有 200 个请求都没有问题地返回。我正在使用 pod 'AWSAPIGateway', '= 2.4.1'
我遇到的问题是 IOS SDK 处理 and/or 收到的 200 响应。我知道它已发送,因为 Cloudwatch 显示了正确的映射,但 IOS 应用程序中没有返回任何内容。
起初我以为我可能与 API 网关自己的响应代码冲突,所以我切换到 403,它不在它的列表中。但这没有用。我也没有收到 500 个响应错误。
这里是调用函数:
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
}
以及 AWS SDK 生成的客户端函数:
- (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]];
}
}
这是错误模型:
@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];
}];
}
这是 API 网关中 400 响应代码的映射:
#set($inputRoot = $input.path('$'))
{
"success" : $input.json('$.success'),
"theFunction" : "foo",
"action" : "foo",
"timeStamp" : "foo",
"error" : "foo",
"data" : $input.json('$.message')
}
这是生成的 Cloudwatch 日志条目:
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
但是我在 iOS 应用程序中没有收到任何回复?
任何对我遗漏的帮助都将不胜感激!
result
时,使用 - continueWithSuccessBlock:
。 - continueWithSuccessBlock:
中的 task
对象始终具有 nil
error
属性。如果你想接收错误,你需要使用 - continueWithBlock:
来代替。
有关详细信息,请参阅 Bolts 文档。