当我发送包含无效数据的突变请求时,我收到以下正文:
{
"data": {
"updateForm": null
},
"errors": [
{
"path": [
"updateForm"
],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "Template transformation yielded an empty response."
}
]
}
我所期望的只是一条消息和一个代码:
{"statusCode":400, "message":"No changes that can be applied to the form"}
我的VTL模板:
#set($slideTypeMap = {
"image": "ImageSlide",
"text": "TextSlide",
"question": "QuestionSlide",
"video": "VideoSlide"})
#set($result = $util.parseJson($context.result.body))
#if($result.slides)
#foreach($slide in $result.slides)
#set($typeName = $slideTypeMap.get($slide.type))
$util.quiet($slide.put("__typename", $typeName))
#end
#end
#if($context.result.statusCode == 200)
$util.toJson($result)
#else
$utils.appendError($context.result.body, "$context.result.statusCode")
#end
应用程序同步日志:
{
"logType": "ResponseMapping",
"path": [
"updateForm"
],
"fieldName": "updateForm",
"resolverArn": "",
"requestId": "",
"context": {
"arguments": {
"id": "e499ad6487ca416081ecc51d959e0fa4",
"input": {
"name": "Image"
}
},
"result": {
"headers": {
"Apigw-Requestid": "",
"content-length": "73",
"Content-Type": "application/json",
"Date": "Fri, 28 Jul 2023 13:30:30 GMT"
},
"statusCode": 400,
"body": "{\"statusCode\":400,\"message\":\"No changes that can be applied to the form\"}"
},
"stash": {},
"outErrors": [
{
"message": "{\"statusCode\":400,\"message\":\"No changes that can be applied to the form\"}",
"type": "400"
}
]
},
"fieldInError": true,
"errors": [
"Unable to transform the template: Template transformation yielded an empty response.."
],
我不能只返回正文数据,因为我在方案中返回了一个带有 id、name...的 Form,并且出现错误,并且有可能为 id、name 返回空值...我需要将来自 API 的消息和代码返回到 Appsync
我所期望的只是一条消息和一个代码:
"statusCode":400, "message":"No changes that can be applied to the form"