2016-07-26 48 views
0

我們遇到了一些麻煩,無法讓我們的策略生效。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標記。

有人知道什麼是錯的嗎?

+0

好的。我們的錯誤...記錄正在工作,但API Management的結果是500內部服務器錯誤,而不是由後端api返回的預期的400錯誤請求。我們是否必須在策略中添加某些內容才能正確處理錯誤?謝謝! –

回答

1

如果在啓用跟蹤的情況下嘗試執行相同請求,會發生什麼情況? https://azure.microsoft.com/en-us/documentation/articles/api-management-howto-api-inspector/

+0

Hi Vitaliy, 啓用跟蹤功能後,顯示解析錯誤。 在處理請求時,忘記在構建深層鏈接注入時使用選擇。所以如果出現錯誤,這個注射也會執行。現在我們檢查引導響應狀態200並處理注入。否則,不採取任何行動。 現在好了!謝謝! –