Microsoft Graph 是一组 API,可用于访问 Microsoft 365 上的数据和见解。 在应用中使用 Microsoft Graph 时,应测试应用如何处理 API 错误。 开发人员代理允许你使用 GraphRandomErrorPlugin
经过 GraphRandomErrorPlugin
优化,可以使用 Microsoft Graph 并模拟 Microsoft Graph 可以返回的特定错误。
若要开始,请在 GraphRandomErrorPlugin
配置文件中启用。
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/rc.schema.json",
"plugins": [
{
"name": "GraphRandomErrorPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
"configSection": "graphRandomErrorPlugin",
"urlsToWatch": [
"https://graph.microsoft.com/v1.0/*",
"https://graph.microsoft.com/beta/*",
"https://graph.microsoft.us/v1.0/*",
"https://graph.microsoft.us/beta/*",
"https://dod-graph.microsoft.us/v1.0/*",
"https://dod-graph.microsoft.us/beta/*",
"https://microsoftgraph.chinacloudapi.cn/v1.0/*",
"https://microsoftgraph.chinacloudapi.cn/beta/*"
]
}
]
}
提示
上面的代码片段侦听所有Microsoft云中Microsoft Graph 的请求。 如果只想模拟特定Microsoft云中的错误,请删除不需要的 URL。
使用配置文件启动开发代理,并使用应用查看它如何处理错误。 对于每个匹配请求,开发代理确定是模拟错误,还是使用 配置的失败率将请求传递到 Microsoft Graph。 当开发代理模拟错误时,它会随机选择Microsoft Graph 使用的错误之一,并向应用返回错误响应。
配置要模拟的错误
默认情况下,模拟 GraphRandomErrorPlugin
以下错误。
HTTP 方法 | 可能的错误 |
---|---|
GET |
429 Too Many Requests 、、500 Internal Server Error 502 Bad Gateway 、503 Service Unavailable 、504 Gateway Timeout |
POST |
429 Too Many Requests 、、500 Internal Server Error 502 Bad Gateway 、503 Service Unavailable 、504 Gateway Timeout 、507 Insufficient Storage |
PUT |
429 Too Many Requests 、、500 Internal Server Error 502 Bad Gateway 、503 Service Unavailable 、504 Gateway Timeout 、507 Insufficient Storage |
PATCH |
429 Too Many Requests 、、500 Internal Server Error 502 Bad Gateway 、503 Service Unavailable 、504 Gateway Timeout |
DELETE |
429 Too Many Requests 、、500 Internal Server Error 502 Bad Gateway 、503 Service Unavailable 、504 Gateway Timeout 、507 Insufficient Storage |
如果要测试特定行为(例如限制),请将插件配置为仅使用 --allowed-errors
选项的相关错误。
devproxy --allowed-errors 429
或者,可以在配置文件中的graphRandomErrorPlugin
对象中配置allowedErrors
属性。
{
"graphRandomErrorPlugin": {
"allowedErrors": [ 429 ]
}
}
模拟 Microsoft Graph 批处理请求中的错误
开发代理以与常规请求相同的方式模拟批处理请求中的错误,以Microsoft Graph。 当开发代理在批处理请求中失败一个或多个请求时,它将返回 424 Failed Dependency
整个批处理请求的响应,就像Microsoft Graph 一样。