您正在查看 Apigee 和 Apigee 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 代理程式未定義「Reset Quota」政策的 <Quota>
元素中指定的配額政策,就會發生這項錯誤。<Quota>
元素為必要元素,可識別目標配額政策,並透過「Reset Quota」政策更新計數器。這個目標配額政策必須在相同的 API Proxy 中建立及定義,且必須在流程中可用。
舉例來說,假設 <Quota>
元素的定義如下,但如果 API Proxy 中未定義 MyQuotaPolicy
,就會出現上述錯誤。
<Quota name="MyQuotaPolicy">
診斷
找出「重設配額」政策中指定的無效配額政策名稱。您可以從錯誤字串中找到配額政策的名稱。例如,在以下錯誤字串中,配額政策名稱為
MyQuotaPolicy:
"faultstring": "Invalid rate limit policy MyQuotaPolicy"
請檢查發生錯誤的 API Proxy 中,每個「Reset Quota」政策。找出特定的「Reset Quota」政策,其中在必要元素
<Quota>
中指定的配額政策,必須與上述步驟 1 中指定的名稱相符。舉例來說,下列「Reset Quota」政策會指定名為
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>
判斷是否在同一個 API Proxy 中建立及定義這項配額政策。如果相同的 API 代理程式中沒有配額政策,則是導致錯誤的原因。
在上述範例中,系統應會在重設配額政策
Reset_Quota_Demo
執行前,先在流程中加入配額政策MyQuotaPolicy
。由於流程中沒有配額政策
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 工具中顯示,顯示為「Reset Quota」政策的錯誤。以下是螢幕截圖範例。
傳回給用戶端的錯誤會簡單地為:policies.ratelimit.QuotaViolation
。
原因
如果無法將政策 <Allow>
元素中包含允許計數的變數參照解析為值,就會發生此錯誤。這個元素為必要元素,可指定減少配額計數器的金額。
診斷
找出發生錯誤的「重設配額」政策,以及無法解析的參照變數名稱。您可以在錯誤回應中找到這兩項項目。
例如,在以下錯誤字串中,政策名稱為
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
在失敗的「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>
判斷在執行「重設配額」政策的流程中,是否已定義並可使用參照變數。
如果變數為:
- 超出範圍 (在執行政策的特定流程中不可用),或
- 無法解析 (未定義)
那就是錯誤的原因。
在上述範例中,
<Allow>
元素中允許的計數值應從名為 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 代理流程中無法使用,就會發生上述錯誤。
<Quota ref="request.header.quotapolicy">
診斷
檢查發生錯誤的 API Proxy 中每個「Reset Quota」政策,並找出「Reset Quota」政策,其中
<Quota>
元素中指定的參照變數名稱無法正確解析。判斷變數是否已在執行「重設配額」政策的流程中定義及可用。
如果變數為:
- 超出範圍 (在政策執行的特定流程中不可用),或
- 無法解析 (未定義)
那就是錯誤的原因。
在下方範例中,系統會從名為 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>
以下是範例 API 要求,其中未將標頭 quotapolicy 傳遞為要求的一部分:
curl -v http://your_host_alias/v1/reset_quota -H "Content-Type: application/json"
其中 your_host_alias 是用於存取 API 的公開網域,如覆寫檔案中的
virtualhosts.hostAliases
屬性所定義。請參閱「指定設定值覆寫值」。由於系統不會將標頭 quotapolicy 當作要求的一部分傳遞,因此在上述「重設配額」政策中,元素
<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
屬性所定義。請參閱「指定設定值覆寫值」。