Microsoft Graph 是 API 的集合,可讓您存取 Microsoft 365 上的數據和深入解析。 當您在應用程式中使用 Microsoft Graph 時,您應該測試應用程式如何處理 API 錯誤。 Dev Proxy 可讓您使用 GraphRandomErrorPlugin 模擬在任何 Microsoft Graph API 上的錯誤。
GraphRandomErrorPlugin已優化以使用 Microsoft Graph,並模擬Microsoft Graph 可以傳回的特定錯誤。
若要開始,請在組態檔中開啟 GraphRandomErrorPlugin 。
{
"$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.0.0/rc.schema.json",
"plugins": [
{
"name": "GraphRandomErrorPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.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。
使用您的組態檔啟動 Dev Proxy,並使用您的應用程式來查看其如何處理錯誤。 針對每個比對要求,Dev Proxy 會決定使用設定的失敗率模擬錯誤或將要求傳遞至 Microsoft Graph。 當 Dev Proxy 模擬錯誤時,它會隨機選取其中一個Microsoft Graph 使用的錯誤,並傳回應用程式的錯誤回應。
設定錯誤以模擬
預設情況下,GraphRandomErrorPlugin 模擬以下錯誤。
| HTTP method (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 Error502 Bad Gateway、503 Service Unavailable、、504 Gateway Timeout、507 Insufficient Storage |
PUT |
429 Too Many Requests、、500 Internal Server Error502 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 Error502 Bad Gateway、503 Service Unavailable、、504 Gateway Timeout、507 Insufficient Storage |
如果您想要測試特定行為,例如流量限制,請將外掛程式設定為只使用由 --allowed-errors 選項指定的相關錯誤。
devproxy --allowed-errors 429
或者,您可以在組態檔中的 allowedErrors 物件中設定 graphRandomErrorPlugin 屬性。
{
"graphRandomErrorPlugin": {
"allowedErrors": [ 429 ]
}
}
在 Microsoft Graph 批次請求中模擬錯誤
Dev Proxy 會以對 Microsoft Graph 一般要求相同的方式,模擬批次要求中的錯誤。 當 Dev Proxy 在批次要求中失敗一個或多個請求時,它會像 Microsoft Graph 一樣,傳回 424 Failed Dependency 作為整個批次要求的回應。