【问题标题】:How can I throw exceptions in set-body in Azure API Management?如何在 Azure API 管理的 set-body 中引发异常?
【发布时间】:2019-09-04 17:15:50
【问题描述】:

当请求正文内部没有特定属性时,我正在处理的 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>

如果有人能提供帮助,我们将不胜感激。

【问题讨论】:

    标签: azure-api-management


    【解决方案1】:

    【讨论】:

    • 谢谢!很久以后才知道的,感谢提供的链接!
    • 没问题,我的荣幸。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多