当请求主体内部没有某些属性时,我正在使用的API现在抛出500 Internal Server Error。我想消除它,而是返回另一个状态代码,例如400 Bad Request。我知道错误是从Azure的APIM返回的,自从我在此反序列化请求正文后,如何将错误扔到set-body策略中?
我已经阅读了许多帖子和文档,但是如果成功了,那是没有运气的。现在是我的代码:
<inbound>
<send-request mode="new" response-variable-name="" timeout="60 sec">
<set-method>POST</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body>@{
var request = context.Request.Body.As<JObject>(preserveContent: true);
if(String.IsNullOrEmpty((string)request["id"])){
WHAT SHOULD I PUT HERE?
}
return request.ToString();
}</set-body>
</send-request>
</inbound>
感谢并感谢有人能帮忙。
答案 0 :(得分:2)