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

您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件
資訊

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> 元素的定義如下所示,但如果 MyQuotaPolicy 未在 API Proxy 中定義,您會收到上述錯誤。

<Quota name="MyQuotaPolicy">

診斷

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

    "faultstring": "Invalid rate limit policy MyQuotaPolicy"
    
  2. 檢查 API Proxy 中發生失敗的所有重設配額政策。找出特定的重設配額政策,其中必要元素 <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 Proxy 中,這就是發生錯誤的原因。

    在上述範例中,在執行重設配額政策 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. 在失敗的重設配額政策 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。如果 allowcount 標頭沒有在 API 要求中傳遞,就會發生此情況。

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

原因

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

舉例來說,如果 <Quota> 元素中的 ref 屬性設為 request.header.quotapolicy,但無法在 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"