> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK 오류 처리 모범 사례

> 여러 언어에 걸쳐 admin, server, client SDK에서 반환되는 PlayFab API 오류를 감지, 검사 및 처리하기 위한 모범 사례입니다.

이 자습서에서는 PlayFab SDK를 사용하여 API 오류에 액세스하고, 인식하고, 처리하는 방법을 보여줍니다.

여기서 설명하는 관행은 admin, server, client SDK에 동일하게 적용되지만, 패턴은 선택한 언어에 *크게* 의존합니다.

간단히 말해, 선택한 패턴은 어떤 SDK(admin/server/client)에도 유효하지만, 구현 세부 사항은 *본인의* 프로그래밍 언어와 환경에 따라 달라집니다.

## 오류 감지 및 액세스

PlayFab SDK는 일반적으로 오류 객체를 반환하여 오류를 보고합니다. 다음 스니펫은 오류를 감지하고 액세스하는 방법을 보여줍니다.

```csharp theme={null}
PlayFabClientAPI.LoginWithEmailAddress(new LoginWithEmailAddressRequest() {
    Email = "doesnotexist@mail.com",
    Password = "nevercorrect",
}, result => {
    // success
}, error => {
    // 'error' object is our point of access to error data
});
```

일반적으로 오류 객체가 정의되어 있으면(null이 아니면) 오류가 발생했음을 나타냅니다. 그런 다음 오류를 추가로 검사할 수 있습니다.

## 오류 검사

오류를 검사하는 가장 일반적인 방법은 코드를 통해 인식하는 것입니다. [글로벌 API 메서드 오류 코드](/services/playfab/api-references/global-api-method-error-codes)에서 설명하는 대로, 생성된 각 오류에는 사람이 읽을 수 있는 오류 코드와 숫자 오류 코드가 포함됩니다.

<Note>
  코드는 *그 자체로* 오류를 인식하고 그에 따라 처리하기에 충분합니다.
</Note>

[LoginWithEmailAddress](xref:titleid.playfabapi.com.client.authentication.loginwithemailaddress) API 메서드를 예로 들어 봅시다. 이 메서드의 [문서](xref:titleid.playfabapi.com.client.authentication.loginwithemailaddress)에 명시된 대로, 실행 시 다음 내부 오류가 발생할 수 있습니다.

* `InvalidTitleId 1004`
* `AccountNotFound 1001`
* `InvalidEmailOrPassword 1142`
* `RequestViewConstraintParamsNotAllowed 1303`

다음 메서드는 이러한 오류를 검사하고 인식하는 방법을 보여줍니다.

```csharp theme={null}
PlayFabClientAPI.LoginWithEmailAddress(new LoginWithEmailAddressRequest() {
    Email = "doesnotexist@mail.com",
    Password = "nevercorrect",
}, result => {
    // success
}, error => {
    // General purpose logging: GenerateErrorReport gives a bunch of information about the error
    Debug.Log(error.GenerateErrorReport());

    // Recognize and handle the error
    switch (error.Error) {
        case PlayFabErrorCode.InvalidTitleId:
            // Handle invalid title id error
            break;
        case PlayFabErrorCode.AccountNotFound:
            // Handle account not found error
            break;
        case PlayFabErrorCode.InvalidEmailOrPassword:
            // Handle invalid email or password error
            break;
        case PlayFabErrorCode.RequestViewConstraintParamsNotAllowed:
            // Handle not allowed view params error
            break;
        default:
            // Handle unexpected error
            break;
    }
});
```

## 오류 처리

오류가 식별되면, 처리/복구 전략은 오류 유형과 특성에 따라 달라집니다. *잘못된 인수*와 같은 오류는 재시도해도 결코 성공하지 못합니다. 해당 API 호출이 성공하려면 요청을 수정해야 합니다.

재시도 전략을 적용할 수 있는 오류의 하위 집합이 있습니다. *재시도 가능한* 오류 유형은 [글로벌 API 메서드 오류 코드](/services/playfab/api-references/global-api-method-error-codes)에 설명되어 있습니다.

재시도 전략을 적용할 때 다음 요구 사항을 충족하도록 하세요.

* 재시도할 때마다 재시도 간 지연 시간이 *기하급수적으로* 증가해야 합니다. 이렇게 하면 성공적인 호출의 가능성이 *증가*하고, 게임이 PlayFab 서버로 스팸 호출을 하는 것을 방지합니다(그러면 *더 많은* 호출이 거부됩니다).

* 이 재시도 전략은 *선택적으로* 적용해야 하며, 재시도할 가치가 있는 코드에만 사용해야 합니다.

재시도해도 안전한 코드 목록은 [글로벌 API 메서드 오류 코드](/services/playfab/api-references/global-api-method-error-codes) 자습서를 참조하세요.


## Related topics

- [오프라인 플레이 처리 모범 사례](/ko/services/xbox-services/develop/best-practices/live-best-practices-offline-play.md)
- [일반적인 오류 사례 처리](/ko/services/playfab/multiplayer/matchmaking/error-cases.md)
- [Economy(레거시)에서의 스토어 및 세일](/ko/services/playfab/economy-monetization/economy/tutorials/stores-and-sales.md)
- [XBOX 서비스 사용자 권한의 클라이언트 측 사용](/ko/services/xbox-services/fundamentals/identity/privileges/concepts/live-user-privileges-client.md)
- [XBOX services 호출 모범 사례](/ko/services/xbox-services/develop/best-practices/live-best-practices-calling-xbl.md)
