如何处理AppSync HTTP解析器响应错误消息?

我正在使用Appsync HTTP解析器从RESTful POST请求模拟/映射。

对于SUCCESS 200案例,一切正常,但我正在寻找一种方法来处理下面的案例422到前端的响应消息。

Users

我的计划

## Raise a GraphQL field error in case of a datasource invocation error
#if($ctx.error)
  $util.error($ctx.error.message,$ctx.error.type)
#end
## If the response is not 201 then return an error. Else return the body **
#if($ctx.result.statusCode == 201)
    #set( $data = $util.parseJson($ctx.result.body))
    $util.toJson($data.product_family)
#elseif($ctx.result.statusCode == 422)
    #set( $data = $util.parseJson($ctx.result.body))
    $util.toJson($data.errors)
#else
    $utils.appendError($ctx.result.body,$ctx.result.statusCode)
#end

但是GraphQL突变总是返回错误消息,例如type Product { id: String name: String desc: String } input ProductInput { name: String! desc: String } type Mutation { createProduct(productInput: ProductInput!): Product }

查询

"message": "Cannot return null for non-nullable type: 'String' within parent Product

我认为响应尝试将错误消息与产品方案映射,但失败

问题:在422的情况下,是否可以向前端返回类似{'error':'Error message'}的消息?如果没有,这种情况的最佳做法是什么?

lk2009xx 回答:如何处理AppSync HTTP解析器响应错误消息?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3162202.html

大家都在问