共用方式為


模擬來自 Microsoft Graph API 的錯誤

Microsoft Graph 是 API 的集合,可讓您存取 Microsoft 365 上的數據和深入解析。 當您在應用程式中使用 Microsoft Graph 時,應該測試應用程式如何處理 API 錯誤。 開發人員 Proxy 可讓您使用 GraphRandomErrorPlugin模擬任何 Microsoft 圖形 API 上的錯誤。

GraphRandomErrorPlugin已優化以使用 Microsoft Graph,並模擬 Microsoft Graph 可以傳回的特定錯誤。

若要啟動,請在組態檔中開啟 GraphRandomErrorPlugin

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.14.1/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。

使用組態檔啟動 Dev Proxy,並使用您的應用程式來查看其如何處理錯誤。 針對每個比對要求,Dev Proxy 會決定要模擬錯誤,或使用 設定的失敗率將要求傳遞至 Microsoft Graph。 當 Dev Proxy 模擬錯誤時,它會隨機選取 Microsoft Graph 使用的其中一個錯誤,並將錯誤回應傳回給您的應用程式。

設定要仿真的錯誤

根據預設,會 GraphRandomErrorPlugin 模擬下列錯誤。

HTTP method 可能的錯誤
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

或者,您可以在 allowedErrors 組態檔中的 graphRandomErrorPlugin 物件中設定 屬性。

{
  "graphRandomErrorPlugin": {
    "allowedErrors": [ 429 ]
  }
}

模擬 Microsoft Graph 批次要求中的錯誤

Dev Proxy 會以與一般要求相同的方式,模擬對 Microsoft Graph 批次要求中的錯誤。 當 Dev Proxy 在批次要求中失敗一或多個要求時,它會傳回 424 Failed Dependency 整個批次要求的回應,就像 Microsoft Graph 一樣。