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

您正在查看 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>