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

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

InvalidMessageWeight

錯誤代碼

policies.ratelimit.InvalidMessageWeight

錯誤回應主體

{
    "fault": {
        "faultstring": "Invalid message weight value [invalid_value]",
        "detail": {
            "errorcode": "policies.ratelimit.InvalidMessageWeight"
        }
    }
}

錯誤訊息示例

{
    "fault": {
        "faultstring": "Invalid message weight value 1.5",
        "detail": {
            "errorcode": "policies.ratelimit.InvalidMessageWeight"
        }
    }
}

原因

如果透過資料流變數指定的 <MessageWeight> 元素值無效 (非整數值),就會發生這個錯誤。

舉例來說,如果為 <MessageWeight> 元素指定的流量變數值為 1.5 (非整數值),就會發生這個錯誤。

診斷

  1. 找出配額政策中 <MessageWeight> 元素所使用的無效值。您可以在錯誤回應的 faultstring 元素中找到這項資訊。舉例來說,在下列錯誤中,<MessageWeight> 元素所用的無效值為 1.5

    "faultstring": "Invalid message weight value 1.5"
    
  2. 在失敗的特定 API Proxy 中檢查所有配額政策。您可以指定一或多個配額政策,其中包含 <MessageWeight> 元素。

    舉例來說,下列政策會透過資料流變數指定<MessageWeight>資料流變數message_weight

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <Quota async="false" continueOnError="false" enabled="true" name="Quota_with_weight" type="calendar">
        <DisplayName>Quota_with_weight</DisplayName>
        <Properties/>
        <Allow count="3"/>
        <Interval>1</Interval>
        <TimeUnit>minute</TimeUnit>
        <StartTime>2017-7-16 12:00:00</StartTime>
        <MessageWeight ref="message_weight"/>
    </Quota>
    
  3. 確認已識別的配額政策中 <MessageWeight> 使用的變數值。您可以從 HTTP 標頭、查詢參數、XML 或 JSON 要求酬載中擷取流量變數的值,也可以在其他政策中定義:

    1. 在第一個定義變數的 API Proxy 組合中找出程式碼。
    2. 找出先定義及填入變數的政策後,請檢查變數值的設定方式。
    3. 如果流量變數值與上方步驟 1 識別的值相符,就表示發生錯誤。

    舉例來說,假設在配額政策之前使用的 JavaScript 政策會根據要求類型,設定變數 message_weight,如下所示:

    var verb = context.getVariable("request.verb");
    context.setVariable("message_weight", "1.5");
    if (verb == 'POST') {
      context.setVariable("message_weight", "2");
    }
    

    請注意,變數 message_weight 的值是 1.5 的無效值 (非整數)。

解析度

確認流程變數指定的 MessageWeight 值是有效值 (整數值)。

如要修正上述範例,您可以將 JavaScript 中變數 message_weight 的值修改為整數。

var verb = context.getVariable("request.verb");
context.setVariable("message_weight", "1");
if (verb == 'POST') {
  context.setVariable("message_weight", "2");
}

FailedToResolveQuotaIntervalReference

錯誤代碼

policies.ratelimit.FailedToResolveQuotaIntervalReference

錯誤回應主體

{
    "fault": {
        "faultstring": "Failed to resolve quota interval reference [reference] in quota policy {1}",
        "detail": {
            "errorcode": "policies.ratelimit.FailedToResolveQuotaIntervalReference"
        }
    }
}

錯誤訊息示例

{
    "fault": {
        "faultstring": "Failed to resolve quota interval reference api.product.developer.quota.interval in quota policy {1}",
        "detail": {
            "errorcode": "policies.ratelimit.FailedToResolveQuotaIntervalReference"
        }
    }
}

原因

如果未在配額政策中定義 <Interval> 元素,就會發生這個錯誤。這個元素為必填項目,用於指定適用於配額的時間間隔。與 <TimeUnit> 元素定義的時間間隔可以是分鐘、小時、天、週或月。

診斷

  1. 檢查失敗的 API Proxy 中的各項配額政策。如果有任何配額政策未定義必要元素 <Interval>,這就是發生錯誤的原因。

    舉例來說,下列配額政策並無必要的元素 <Interval>

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <Quota async="false" continueOnError="false" enabled="true" name="CheckQuota" type="calendar">
        <DisplayName>CheckQuota</DisplayName>
        <Properties/>
        <Allow count="3"/>
            <TimeUnit ref="verifyapikey.verify-api-key.apiproduct.developer.quota.timeunit">hour</TimeUnit>
        <StartTime>2017-7-16 12:00:00</StartTime>
    </Quota>
    

    由於上述配額政策並未定義必要元素 <TimeUnit>,因此您會收到錯誤代碼:

    policies.ratelimit.FailedToResolveQuotaIntervalReference
    

解析度

請確認特定 API Proxy 的所有配額政策均已正確定義必要元素 <Interval>

如要修正上述範例,可以修改政策來加入元素 <Interval>,如下所示。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Quota async="false" continueOnError="false" enabled="true" name="CheckQuota" type="calendar">
    <DisplayName>CheckQuota</DisplayName>
    <Properties/>
    <Allow count="3"/>
    <TimeUnit ref="verifyapikey.verify-api-key.apiproduct.developer.quota.timeunit">hour</TimeUnit>
    <Interval ref="verifyapikey.verify-api-key.apiproduct.developer.quota.interval">1</Interval>
    <StartTime>2017-7-16 12:00:00</StartTime>
</Quota>

FailedToResolveQuotaIntervalTimeUnitReference

錯誤代碼

policies.ratelimit.FailedToResolveQuotaIntervalTimeUnitReference

錯誤回應主體

{
    "fault": {
        "faultstring": "Failed to resolve quota time unit reference [reference] in quota policy {1}",
        "detail": {
            "errorcode": "policies.ratelimit.FailedToResolveQuotaIntervalTimeUnitReference"
        }
    }
}

錯誤訊息示例

{
    "fault": {
        "faultstring": "Failed to resolve quota time unit reference apiproduct.developer.quota.timeunity in quota policy {1}",
        "detail": {
            "errorcode": "policies.ratelimit.FailedToResolveQuotaIntervalTimeUnitReference"
        }
    }
}

原因

如果未在配額政策中定義 <TimeUnit> 元素,就會發生這個錯誤。此為必要元素,用於指定配額適用的時間單位。時間間隔可以以分鐘、小時、天、週或月為單位。

診斷

  1. 檢查失敗的 API Proxy 中的各項配額政策。如果有任何配額政策未定義必要元素 <TimeUnit>,這就是發生錯誤的原因。

    舉例來說,下列配額政策沒有必要的元素 <TimeUnit>

    <Quota async="false" continueOnError="false" enabled="true" name="CheckQuota" type="calendar">
      <DisplayName>CheckQuota</DisplayName>
      <Properties/>
      <Allow count="3"/>
          <Interval ref="verifyapikey.verify-api-key.apiproduct.developer.quota.interval">1</Interval>
      <StartTime>2017-7-16 12:00:00</StartTime>
    </Quota>
    

    由於上述配額政策並未定義必要元素 <TimeUnit>,因此您會收到錯誤代碼:

    policies.ratelimit.FailedToResolveQuotaIntervalTimeUnitReference
    

解析度

確認特定 API Proxy 的所有配額政策都已定義必要的元素 <TimeUnit>

如要修正上述範例,可以修改政策來加入元素 <TimeUnit>,如下所示。

<Quota async="false" continueOnError="false" enabled="true" name="CheckQuota" type="calendar">
    <DisplayName>CheckQuota</DisplayName>
    <Properties/>
    <Allow count="3"/>
    <TimeUnit ref="verifyapikey.verify-api-key.apiproduct.developer.quota.timeunit">hour</TimeUnit>
    <Interval ref="verifyapikey.verify-api-key.apiproduct.developer.quota.interval">1</Interval>
    <StartTime>2017-7-16 12:00:00</StartTime>
</Quota>