Events
Microsoft 365 Community Conference
May 6, 2 PM - May 9, 12 AM
Skill up for the era of AI at the ultimate community-led Microsoft 365 event, May 6-8 in Las Vegas.
Learn moreThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
When building apps, you should test how your app handles API errors. Dev Proxy allows you to simulate errors on any API that you use in your app using the GenericRandomErrorPlugin.
To start, enable the GenericRandomErrorPlugin
in your configuration file.
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/rc.schema.json",
"plugins": [
{
"name": "GenericRandomErrorPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
"configSection": "errorsContosoApi",
"urlsToWatch": [
"https://api.contoso.com/*"
]
}
]
}
Tip
Because each API is different, you typically configure an instance of the GenericRandomErrorPlugin
for each API you want to simulate errors on. To make it easier to manage the configuration, name the configSection
after the API you want to simulate errors on. Additionally, specify the URLs that you want to simulate errors on in the urlsToWatch
property with the plugin. This will make it easier to manage the configuration and reuse it in the future.
Next, configure the plugin to use a file that contains the errors you want to simulate.
{
"errorsContosoApi": {
"errorsFile": "errors-contoso-api.json"
}
}
Finally, in the errors file, define the list of error responses that you want to simulate. For example, to simulate a 500 error with a custom JSON response, use the following configuration:
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/genericrandomerrorplugin.schema.json",
"errors": [
{
"request": {
"url": "https://api.contoso.com/*"
},
"responses": [
{
"statusCode": 500,
"headers": [
{
"name": "content-type",
"value": "application/json; charset=utf-8"
}
],
"body": {
"code": "InternalServerError",
"message": "Something went wrong"
}
}
]
}
]
}
You can define as many error responses as you need.
Start Dev Proxy with your configuration file and use your app to see how it handles the errors. For each matching request, Dev Proxy determines whether to simulate an error or pass the request through to the original API using the configured failure rate. When Dev Proxy simulates an error, it uses a random error from the array of error responses you defined in the configuration file.
If you use mocks in your configuration file, you can temporarily disable them by using the --no-mocks
option.
devproxy --no-mocks
Learn more about the GenericRandomErrorPlugin
.
Dev Proxy feedback
Dev Proxy is an open source project. Select a link to provide feedback:
Events
Microsoft 365 Community Conference
May 6, 2 PM - May 9, 12 AM
Skill up for the era of AI at the ultimate community-led Microsoft 365 event, May 6-8 in Las Vegas.
Learn moreTraining
Module
Test your app like a pro - Training
Learn how to test your app from Power Apps like a professional.