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

한눈에 보기
목표: 앱에서 Microsoft Graph API 오류를 처리하는 방법 테스트
시간: 10분
플러그 인:GraphRandomErrorPlugin
필수 구성 요소:개발 프록시 설정

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

Microsoft GraphRandomErrorPlugin Graph를 사용하도록 최적화되고 Microsoft Graph에서 반환할 수 있는 특정 오류를 시뮬레이션합니다.

구성 파일에서 GraphRandomErrorPlugin을(를) 사용하도록 설정합니다.

파일: devproxyrc.json

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v4.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 속성을 구성할 수 있습니다.

파일: devproxyrc.json

{
  "graphRandomErrorPlugin": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v4.0.0/graphrandomerrorplugin.schema.json",
    "allowedErrors": [ 429 ]
  }
}

개발 프록시는 이전 표에 나열된 대로 각 HTTP 메서드에 적용되는 허용된 오류만 사용합니다. 허용되는 오류가 메서드에 적용되지 않는 경우 Dev Proxy는 해당 메서드를 사용하는 요청을 Microsoft Graph로 전달합니다. 예를 들어 507만 허용하면 Dev Proxy가 POST, PUT, DELETE 요청을 실패시키고, GET 및 PATCH 요청은 통과시킵니다. 또한 개발자 프록시는 HEAD 또는 OPTIONS와 같이 테이블에 나열되지 않은 메서드를 사용하는 요청도 전달합니다.

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

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

일괄 처리의 요청에서 허용된 오류 중 어느 것도 적용되지 않는 메서드를 사용하는 경우 일괄 처리 응답에 일괄 처리의 모든 요청에 대한 응답이 포함되어야 하므로 Dev Proxy는 전체 일괄 처리를 Microsoft Graph로 전달합니다.

참고하십시오