Amazon web services AppSync验证错误不存在';响应映射模板中的t触发器错误处理程序

Amazon web services AppSync验证错误不存在';响应映射模板中的t触发器错误处理程序,amazon-web-services,amazon-dynamodb,aws-appsync,Amazon Web Services,Amazon Dynamodb,Aws Appsync,我正在使用AppSync,验证错误似乎不会触发响应映射模板中的错误捕获。 属性值包含一个AWSPhone输入。 如果我为AWSPhone输入了错误的格式,则错误(如预期的)为: 我的请求映射模板如下所示: { "version": "2018-05-29", "operation": "PutItem", "key": { "id": $util.dynamodb.toDynamoDBJson($ctx.args.input.client), }, "attribut

我正在使用AppSync,验证错误似乎不会触发响应映射模板中的错误捕获。 属性值包含一个AWSPhone输入。 如果我为AWSPhone输入了错误的格式,则错误(如预期的)为:

我的请求映射模板如下所示:

{
  "version": "2018-05-29",
  "operation": "PutItem",
  "key": {
    "id": $util.dynamodb.toDynamoDBJson($ctx.args.input.client),
  },
  "attributeValues": $util.dynamodb.toMapValuesJson($ctx.args.input),
}
我的响应映射模板:

#if($ctx.error)
  $util.error("Custom error response")
#end
  $util.toJson($ctx.result)
很明显,确实发生了错误,但它不会触发我的响应模板中的案例。 如何返回验证错误的自定义消息?
在这种情况下可能吗?

根据您提供的信息,您的
PutItem
操作似乎成功并返回了您放在
$ctx.result
字段中的项目。然后,当AppSync试图将响应映射模板输出上的一个字段强制为AWSPhone时,它失败了,出现了您提到的验证错误

#if($ctx.error)$util.error(“自定义错误响应”)
将只捕获DynamoDB错误。从结果到字段输出类型的GraphQL强制在模板求值后发生

解决这个问题的一种方法是在将请求映射模板保存到DynamoDB或将DynamoDB返回的值更改为正确的AWSPhone标量格式之前,将验证添加到请求映射模板中

#if($ctx.error)
  $util.error("Custom error response")
#end
  $util.toJson($ctx.result)