【问题标题】:AWS API Gateway exported IOS SDK no error responseAWS API Gateway 导出 IOS SDK 无错误响应
【发布时间】:2016-05-14 02:36:38
【问题描述】:

我正在使用导出的 API Gateway IOS SDK。 API 最初是通过 Swagger 作为模板导入 API Gateway 的,但后来使用 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 Gateway 中 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 应用程序中什么也没收到?

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

【问题讨论】:

  • 您要考虑导出为 Swagger 规范,然后使用swagger-codegen 生成 ObjC SDK(附带自动生成的文档)

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


【解决方案1】:

- continueWithSuccessBlock: 用于仅从任务对象中提取 result 时使用。 - continueWithSuccessBlock: 中的 task 对象始终具有 nil error 属性。如果你想接收错误,你需要改用- continueWithBlock:

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

【讨论】:

  • 就是这样!如果它是一条蛇,它会咬我的
猜你喜欢
  • 2017-08-08
  • 2018-03-22
  • 1970-01-01
  • 2018-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-21
  • 2016-04-16
相关资源
最近更新 更多