重設配額執行階段錯誤疑難排解

查看 Apigee Edge 說明文件。
前往 Apigee X 說明文件
info

InvalidRLPolicy

錯誤代碼

policies.resetquota.InvalidRLPolicy

錯誤回應主體

{
    "fault": {
        "faultstring": "Invalid rate limit policy quota_policy_name",
        "detail": {
            "errorcode": "policies.resetquota.InvalidRLPolicy"
        }
    }
}

錯誤訊息示例

{
    "fault": {
        "faultstring": "Invalid rate limit policy MyQuotaPolicy",
        "detail": {
            "errorcode": "policies.resetquota.InvalidRLPolicy"
        }
    }
}

原因

如果應用程式的 <Quota> 元素中指定配額政策,就會發生這個錯誤。 API Proxy 中未定義重設配額政策。<Quota> 元素為必要元素,可識別目標配額政策,並透過「重設配額」政策更新計數器。必須在以下範圍內建立及定義這項目標配額政策: 您必須使用相同的 API Proxy,而且在流程中也必須保持可用

舉例來說,假設 <Quota> 元素定義如下所示,但 未在 API Proxy 中定義 MyQuotaPolicy,接著會收到上述錯誤。

<Quota name="MyQuotaPolicy">

診斷

  1. 找出重設配額政策中指定的無效配額政策名稱。 您可以在錯誤字串中找到配額政策的名稱。例如,在 以下錯誤字串,配額政策名稱為 MyQuotaPolicy:

    "faultstring": "Invalid rate limit policy MyQuotaPolicy"
    
  2. 在失敗時,檢查 API Proxy 中的各項重設配額政策 。找出特定的「Reset Quota」政策,其中在必要元素 <Quota> 中指定的配額政策,必須與上述步驟 1 中指定的名稱相符。

    舉例來說,下列「重設配額」政策指定了名為「配額」的「配額」政策 MyQuotaPolicy,與錯誤字串中的內容相符:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <ResetQuota async="false" continueOnError="false" enabled="true" name="Reset_Quota_Demo">
        <DisplayName>Reset_Quota_Demo</DisplayName>
        <Properties/>
        <Quota name="MyQuotaPolicy">
           <Identifier name="identifierName" ref="request.header.identifier">
                <Allow>100</Allow>
            </Identifier>
        </Quota>
    </ResetQuota>
    
    
  3. 決定是否要在同一個 API Proxy 中建立及定義這項配額政策。 如果同一個 API 代理程式中沒有配額政策,則會導致錯誤。

    在上述範例中,系統應會在重設配額政策 Reset_Quota_Demo 執行前,先在流程中加入配額政策 MyQuotaPolicy

    由於流程中沒有配額政策 MyQuotaPolicy,因此您會收到以下錯誤代碼:

"errorcode": "policies.resetquota.InvalidRLPolicy"

解析度

確認 <Quota> 元素中宣告的配額政策已定義於 並存取 API Proxy必須在重設配額政策時提供這項目標配額政策 執行作業。

FailedToResolveAllowCountRef

錯誤代碼

policies.resetquota.FailedToResolveAllowCountRef

錯誤回應主體

Failed to resolve allow count reference reference_name for identifier identifier_name
in ResetQuotaStepDefinition:policy_name;API Proxy:proxy_name;Revision:
revision_number;Environment:env_name;Organization:org_name

錯誤訊息示例

Failed to resolve allow count reference request.header.allowcount for identifier
identifierName in ResetQuotaStepDefinition:ResetQuota;API Proxy:Reset_Quota;
Revision:10;Environment:test;Organization:demo

傳回用戶端的錯誤就是:policies.ratelimit.QuotaViolation

原因

如果無法將政策 <Allow> 元素中包含允許計數的變數參照解析為值,就會發生此錯誤。這個 元素是必要元素,並指定配額計數器的減少幅度。

診斷

  1. 找出發生錯誤的「重設配額」政策,以及無法解析的參照變數名稱。你可以找到這兩項資訊 。

    舉例來說,在下列錯誤字串中,政策名稱為 ResetQuota 且 參照為 request.header.allowcount

    Failed to resolve allow count reference request.header.allowcount for identifier
    identifierName in ResetQuotaStepDefinition:ResetQuota;API Proxy:Reset_Quota;
    Revision:10;Environment:test;Organization:demo
    
  2. 在失敗的「Reset Quota」政策 XML 中,請確認所用參照變數的名稱與錯誤回應中指定的參照名稱相符 (上方步驟 1)。

    舉例來說,下列政策會為元素設定名稱為 request.header.allowcount,與錯誤中出現的內容相符:

    <ResetQuota async="false" continueOnError="false" enabled="true" name="ResetQuota">
        <DisplayName>ResetQuota</DisplayName>
        <Properties/>
        <Quota name="MyQuotaPolicy">
            <Identifier name="identifierName">
                <Allow ref="request.header.allowcount"/>
            </Identifier>
        </Quota>
    </ResetQuota>
    
  3. 確定是否已定義參照變數,且可用於 系統就會執行「重設配額」政策。

  4. 如果變數為:

    1. 超出範圍 (不適用於執行政策的特定流程)
    2. 無法解析 (未定義)

    這就是發生錯誤的原因

    在上述範例中,<Allow> 元素中允許的計數值應從名為 allowcount 的要求標頭中擷取。不過 Edge 無法解析 request.header.allowcount。會發生這種情形 不會在 API 要求中傳送 allowcount 標頭。

    以下 API 要求範例未傳送 allowcount 標頭 的要求:

    curl -v http://demo-eval-test.apigee.net/v1/reset_quota -H "Content-Type: application/json"
    

    由於標頭 allowcount 並未以要求的一部分傳遞,因此上述「重設配額」政策中元素 <Allow> 使用的變數 request.header.allowcount 未定義,因此無法解析。因此,您會收到以下錯誤回應:

    Failed to resolve allow count reference request.header.allowcount for identifier
    identifierName in ResetQuotaStepDefinition:ResetQuota;API Proxy:Reset_Quota;
    Revision:10;Environment:test;Organization:demo
    

解析度

確認 <Allow> 元素中參照的變數已存在/已定義 可用狀態,也就是執行重設配額政策的特定流程。

如要修正上述範例,請修改要求,在當中加入 allowcount 標頭,如下所示:

curl -v http://demo-eval-test.apigee.net/v1/reset_quota -H "Content-Type: application/json" -H "allowcount:30"

FailedToResolveRLPolicy

錯誤代碼

policies.resetquota.FailedToResolveRLPolicy

錯誤回應主體

{
    "fault": {
        "faultstring": "Failed to resolve rate limit policy",
        "detail": {
            "errorcode": "policies.resetquota.FailedToResolveRLPolicy"
        }
    }
}

錯誤訊息示例

{
    "fault": {
        "faultstring": "Failed to resolve rate limit policy",
        "detail": {
            "errorcode": "policies.resetquota.FailedToResolveRLPolicy"
        }
    }
}

原因

如果 ref 屬性參照的變數位於 <Quota> 元素無法解析。

舉例來說,如果帳戶中的 ref 屬性設為 request.header.quotapolicy <Quota> 元素,但不在 API Proxy 流程中,那麼 。

<Quota ref="request.header.quotapolicy">

診斷

  1. 在失敗時,檢查 API Proxy 中的各項重設配額政策 並找出參照名稱的重設配額政策 無法正確解析 <Quota> 元素中指定的變數。

  2. 確定變數是否已定義且可在 可重設配額政策執行作業。

  3. 如果變數為以下任一變數:

    1. 超出範圍 (不適用於執行政策的特定流程)
    2. 無法解析 (未定義)

    這就是發生錯誤的原因

    在下方範例中,目標配額政策的名稱應為 從名為 quotapolicy 的要求標頭中擷取。但 Edge 無法 解析 request.header.quotapolicy。如果標頭為 quotapolicy,就會發生這種情況 未做為 API 要求的一部分傳遞。

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <ResetQuota async="false" continueOnError="false" enabled="true" name="Reset_Quota_Demo">
        <DisplayName>Reset_Quota_Demo</DisplayName>
        <Properties/>
        <Quota ref="request.header.quotapolicy">
            <Identifier name="identifierName" ref="request.header.identifier">
                <Allow>100</Allow>
            </Identifier>
        </Quota>
    </ResetQuota>
    

    以下 API 要求範例不傳遞 quotapolicy , 部分:

    curl -v http://demo-eval-test.apigee.net/v1/reset_quota -H "Content-Type: application/json"
    

    由於標頭 quotapolicy 並未做為要求的一部分進行傳送,因此參照 上述「重設」元素 <Quota> 元素中使用的 request.header.quotapolicy 配額政策未定義,因此無法解析。因此,您會收到以下錯誤回應:

    "errorcode": "policies.resetquota.FailedToResolveRLPolicy"
    

解析度

請確認 <Quota> 元素中參照的屬性 ref 會在執行階段解析,且可在執行「重設配額」政策的特定流程中使用。

如要修正上述範例,可以修改要求來納入 quotapolicy 標頭,如下所示:

curl -v http://demo-eval-test.apigee.net/v1/reset_quota -H "Content-Type: application/json" -H "quotapolicy:MyQuotaPolicy"