GenericRandomErrorPlugin

Fails requests with a random selected error from file containing mocked errors.

Screenshot of a command prompt with the Dev Proxy simulating one of the errors for an OpenAI API request as defined in the config file.

Configuration example

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

Configuration properties

Property Description Default
errorsFile Path to the file that contains error responses. errors.json
rate The percentage of requests to fail with a random error. Value between 0 and 100. 50
retryAfterInSeconds The number of seconds to wait before retrying the request. Included on the Retry-After response header for dynamic throttling. 5

Command line options

Name Description Default
-f, --failure-rate <failure rate> The percentage of requests to fail with a random error. Value between 0 and 100. 50

Remarks

Response body

If you set the body property of an error response to a JSON object or array, Dev Proxy serializes it to JSON. If you set it to a string, Dev Proxy sends the string as-is, without surrounding quotes. A string that starts with @ is treated as a path to a file, relative to the errors file, with the response body. Because Dev Proxy defaults the Content-Type header to application/json, set the Content-Type header to match your content when you return non-JSON content, for example text/plain.

Per-response Retry-After values

Dev Proxy resolves @dynamic in the Retry-After header for any status code, like 429, 503, or 529. It matches the header name regardless of case. When it resolves @dynamic, it also registers the request with the RetryAfterPlugin, which reports requests that your app sends before the Retry-After time is up.

By default, the Retry-After header uses the global retryAfterInSeconds value. You can override this value on a per-response basis using the @dynamic=N syntax in the error responses file, where N is the number of seconds to wait before retrying.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v4.0.0/genericrandomerrorplugin.errorsfile.schema.json",
  "errors": [
    {
      "request": {
        "url": "https://api.openai.com/*"
      },
      "responses": [
        {
          "statusCode": 429,
          "headers": [
            {
              "name": "Retry-After",
              "value": "@dynamic=17"
            }
          ],
          "body": {
            "error": {
              "message": "Rate limit exceeded. Wait 17 seconds."
            }
          }
        }
      ]
    }
  ]
}

In this example, the Retry-After header uses 17 seconds for this response, regardless of the global retryAfterInSeconds setting. The value increments on each subsequent throttled request, as with the plain @dynamic token.

Default Content-Type header

If an error response has a body and doesn't define a Content-Type header, Dev Proxy returns the response with the Content-Type: application/json header. To return a different content type, add the Content-Type header to the response in the errors file. Dev Proxy uses the value that you specify.

Next step