配额运行时错误问题排查

您正在查看的是 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 代理中的所有配额政策。可能存在一个或多个指定了 <MessageWeight> 元素的配额政策。

    例如,以下政策通过流变量 message_weight 指定 <MessageWeight>

    <?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 代理软件包中找到代码。
    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 代理中的每个配额政策。如果存在任何未定义必需的 <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 代理的所有配额政策都已正确定义必需的 <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 代理中的每个配额政策。如果存在任何未定义必需的 <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 代理的所有配额政策均已定义必需的 <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>