AWS API网关导出IOS SDK无错误响应



我正在使用导出的API网关IOS SDK。API最初通过Swagger作为模板导入API网关,但后来通过AWS门户进行了修改,以映射回IOS SDK中的响应模型和类。所有200个请求都被毫无问题地返回。我正在使用吊舱"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应用程序中没有收到任何回复?

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

当您只想从任务对象中提取result时,会使用

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

有关更多详细信息,请参阅螺栓文档。

相关内容

  • 没有找到相关文章

最新更新