【发布时间】:2019-10-22 02:35:48
【问题描述】:
我正在使用 AppSync,并且似乎验证错误不会触发响应映射模板中的错误捕获。 属性值包含 AWSPhone 输入。 如果我为 AWSPhone 输入了错误的格式,错误(如预期)是:
{
"data": null,
"errors": [
{
"path": null,
"locations": [
{
"line": 2,
"column": 17,
"sourceName": null
}
],
"message": "Validation error of type WrongType: argument 'input.company.phoneNumber' with value 'StringValue{value='+1-541-754-300'}' is not a valid 'AWSPhone' @ 'createProfile'"
}
]
}
我的请求映射模板是这样的:
{
"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)
很明显确实发生了错误,但它不会触发我的响应模板中的案例。 如何为验证错误返回自定义消息? 在这种情况下甚至可能吗?
【问题讨论】:
标签: amazon-web-services amazon-dynamodb aws-appsync