我們遇到了一些麻煩,無法讓我們的策略生效。Azure Api管理中的此發送單向請求有什麼問題
我們希望在出現大於或等於400的錯誤的情況下登錄到外部用戶(Loggly)。我們認爲這是在出站部分處理的,可以通過發送單向請求來實現。我們還嘗試通過策略的錯誤部分進行登錄。
代碼:
<policies>
<inbound>
</inbound>
<backend>
</backend>
<outbound>
<choose>
<when condition="@(context.Response.StatusCode >= 400)">
<send-one-way-request mode="new">
<set-url>http://logs-01.loggly.com/inputs/<uid>/tag/Api_Azure</set-url>
<set-method>POST</set-method>
<set-body>@{
return new JObject(
new JProperty("username","APIM Alert"),
new JProperty("icon_emoji", ":ghost:"),
new JProperty("text", String.Format("{0} {1}\nHost: {2}\n{3} {4}\n User: {5}",
context.Request.Method,
context.Request.Url.Path + context.Request.Url.QueryString,
context.Request.Url.Host,
context.Response.StatusCode,
context.Response.StatusReason,
context.User.Email
))
).ToString();
}</set-body>
</send-one-way-request>
</when>
</choose>
</outbound>
<on-error>
<send-one-way-request mode="new">
<set-url>http://logs-01.loggly.com/inputs/<uid>/tag/Api_Azure</set-url>
<set-method>POST</set-method>
<set-body>TEST outbound ERROR: @(context.LastError.Message)</set-body>
</send-one-way-request>
</on-error>
</policies>
這一政策的結果是,請求通過發送-單向發送請求,但在這種情況下使用的URL是原來的URL,而不是一個在set-url標記。
有人知道什麼是錯的嗎?
好的。我們的錯誤...記錄正在工作,但API Management的結果是500內部服務器錯誤,而不是由後端api返回的預期的400錯誤請求。我們是否必須在策略中添加某些內容才能正確處理錯誤?謝謝! –