AWS API Gateway导出的IOS SDK没有错误响应

时间:2016-05-12 20:34:56

标签: ios amazon-web-services httpresponse aws-sdk aws-api-gateway

我正在使用导出的API Gateway IOS SDK。 API最初通过Swagger作为模板导入API网关,但是经过AWS门户修改后映射回IOS SDK中的响应模型和类。返回所有200个请求没有问题。我正在使用pod' AWSAPIGateway',' = 2.4.1'

我遇到的问题不是其他问题,而是由IOS SDK处理和/或接收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应用程序中没有收到任何内容?

对我所缺少的任何帮助都将不胜感激!

1 个答案:

答案 0 :(得分:1)

当您只想从任务对象中提取- continueWithSuccessBlock:时,使用

resulttask中的- continueWithSuccessBlock:对象始终具有nil error属性。如果您想收到错误,则需要使用- continueWithBlock:

有关详细信息,请参阅Bolts文档。