更改请求失败率

概览
目标: 配置 Dev Proxy 模拟 API 故障的频率
时间: 2 分钟
先决条件:设置开发代理

默认情况下,开发代理为 API 返回随机错误的可能性为 50%。 可以使用选项将可能性更改为其他值 --failure-rate ,例如:

devproxy --failure-rate 80

或者,可以在开发代理配置文件中配置失败率。

文件: devproxyrc.json

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/rc.schema.json",
  "plugins": [
    {
      "name": "GenericRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
      "configSection": "genericRandomErrorPlugin"
    }
  ],
  "urlsToWatch": [
    "https://api.example.com/*"
  ],
  "genericRandomErrorPlugin": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/genericrandomerrorplugin.schema.json",
    "errorsFile": "errors.json",
    "rate": 80
  }
}

重要

将失败率配置为 0 时,开发代理会将所有请求传递到原始 API。 将其配置为 100 时,开发代理将模拟每个匹配请求的错误。

另请参阅