다음을 통해 공유


Microsoft Graph API에서 오류 시뮬레이션

Microsoft Graph는 Microsoft 365의 데이터 및 인사이트에 액세스할 수 있는 API 컬렉션입니다. 앱에서 Microsoft Graph를 사용하는 경우 앱에서 API 오류를 처리하는 방법을 테스트해야 합니다. 개발자 프록시는 GraphRandomErrorPlugin을 사용하여 모든 Microsoft Graph API에서 오류를 시뮬레이션할 수 있도록 합니다.

Microsoft GraphRandomErrorPlugin 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는 구성된 실패율을 사용하여 오류를 시뮬레이션할지 아니면 Microsoft Graph에 요청을 전달할지 결정합니다. 개발자 프록시는 오류를 시뮬레이트할 때 Microsoft Graph에서 사용하는 오류 중 하나를 임의로 선택하고 앱에 오류 응답을 반환합니다.

시뮬레이션할 오류 구성

기본적으로 다음 GraphRandomErrorPlugin 오류를 시뮬레이션합니다.

HTTP 메서드 가능한 오류
GET 429 Too Many Requests, 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable504 Gateway Timeout
POST 429 Too Many Requests, 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout507 Insufficient Storage
PUT 429 Too Many Requests, 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout507 Insufficient Storage
PATCH 429 Too Many Requests, 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable504 Gateway Timeout
DELETE 429 Too Many Requests, 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout507 Insufficient Storage

특정 동작, 예를 들어 제한을 테스트하려면, --allowed-errors 옵션을 사용하여 관련 오류만 처리하도록 플러그인을 설정합니다.

devproxy --allowed-errors 429

또는 구성 파일의 allowedErrors 개체에서 graphRandomErrorPlugin 속성을 구성할 수 있습니다.

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

Microsoft Graph 일괄 처리 요청의 오류 시뮬레이션

개발자 프록시는 일반 요청과 동일한 방식으로 Microsoft Graph에 대한 일괄 처리 요청의 오류를 시뮬레이션합니다. 개발자 프록시가 일괄 처리 요청에서 하나 이상의 요청에 실패하면 Microsoft Graph와 마찬가지로 전체 일괄 처리 요청에 대한 응답을 반환 424 Failed Dependency 합니다.