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

您目前查看的是 ApigeeApigee Hybrid 說明文件。
查看 Apigee Edge 說明文件。

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"
        }
    }
}

原因

如果 API Proxy 中未定義「重設配額」政策 <Quota> 元素指定的配額政策,就會發生這項錯誤。<Quota> 元素為必要元素,用於識別目標配額政策,其計數器應透過重設配額政策更新。這個目標配額政策必須在同一個 API Proxy 中建立及定義,且必須在流程中可用。

舉例來說,假設 <Quota> 元素定義如下,但如果 API Proxy 中未定義 MyQuotaPolicy,就會發生上述錯誤。

<Quota name="MyQuotaPolicy">

診斷

  1. 找出重設配額政策中指定的無效配額政策名稱。 您可以從 faultstring 找到配額政策名稱。舉例來說,在下列 faultstring 中,配額政策名稱為 MyQuotaPolicy:

    "faultstring": "Invalid rate limit policy MyQuotaPolicy"
    
  2. 檢查發生失敗的 API Proxy 中的每項重設配額政策。找出特定「重設配額」政策,其中強制元素 <Quota> 內指定的配額政策與上述步驟 1 中識別的名稱相符。

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

    <?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 Proxy 中沒有配額政策,這就是錯誤原因。

    在上述範例中,配額政策 MyQuotaPolicy 應存在於流程中,然後再執行重設配額政策 Reset_Quota_Demo

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

"errorcode": "policies.resetquota.InvalidRLPolicy"

解析度

請確認 <Quota> 元素中宣告的配額政策已在 API 代理程式中定義。重設配額政策執行時,必須提供這項目標配額政策。

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

注意:上述錯誤訊息不會做為回應傳送給用戶端。這只會顯示在 Trace 工具中,表示「重設配額」政策發生錯誤。下方是螢幕截圖範例。

在「屬性」下方,錯誤列會填入訊息。

傳回給用戶端的錯誤會是 policies.ratelimit.QuotaViolation

原因

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

診斷

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

    舉例來說,在下列 faultstring 中,政策名稱為 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. 在重設配額政策 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」allowcount的要求標頭擷取。不過,Apigee 無法解析 request.header.allowcount。如果未將標頭 allowcount 做為 API 要求的一部分傳遞,就會發生這種情況。

    以下是範例 API 要求,未將標頭 allowcount 做為要求的一部分傳送:

    curl -v http://your_host_alias/v1/reset_quota -H "Content-Type: application/json"
    

    其中 your_host_alias 是用於存取 API 的公開網域,已在覆寫檔案的 virtualhosts.hostAliases 屬性中設定。請參閱「指定設定覆寫」。

    由於標頭 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://your_host_alias/v1/reset_quota -H "Content-Type: application/json" -H "allowcount:30"

其中 your_host_alias 是用於存取 API 的公開網域,已在覆寫檔案的 virtualhosts.hostAliases 屬性中設定。請參閱「指定設定覆寫」。

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"
        }
    }
}

原因

如果無法解析 <Quota> 元素中 ref 屬性參照的變數,就會發生這項錯誤。

舉例來說,如果 ref 屬性在 <Quota> 元素中設為 request.header.quotapolicy,但 API Proxy 流程中沒有這個屬性,就會發生上述錯誤。

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

診斷

  1. 檢查發生失敗的 API Proxy 中的每個「重設配額」政策,找出 <Quota> 元素中指定的參照變數名稱無法正確解析的「重設配額」政策。

  2. 判斷變數是否已定義,且可在執行「重設配額」政策的流程中使用。

  3. 如果變數為下列任一值:

    1. 超出範圍 (政策執行時無法使用),或
    2. 無法解析 (未定義)

    這就是錯誤原因。

    在下方範例中,目標配額政策的名稱應從名為「quotapolicy」的要求標頭中擷取。不過,Apigee 無法解析 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>
    

    以下是未將標頭 quotapolicy 做為要求一部分傳送的 API 要求範例:

    curl -v http://your_host_alias/v1/reset_quota -H "Content-Type: application/json"
    

    其中 your_host_alias 是用於存取 API 的公開網域,已在覆寫檔案的 virtualhosts.hostAliases 屬性中設定。請參閱「指定設定覆寫」。

    由於標頭 quotapolicy 未做為要求的一部分傳遞,因此上述「Reset Quota policy」中的元素 <Quota> 所使用的參照 request.header.quotapolicy 未定義,且無法解析。因此,您會收到以下錯誤回應:

    "errorcode": "policies.resetquota.FailedToResolveRLPolicy"
    

解析度

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

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

curl -v http://your_host_alias/v1/reset_quota -H "Content-Type: application/json" -H "quotapolicy:MyQuotaPolicy"

其中 your_host_alias 是用於存取 API 的公開網域,已在覆寫檔案的 virtualhosts.hostAliases 屬性中設定。請參閱「指定設定覆寫」。