question

Chris B. avatar image
Chris B. asked

Error codes on unity

I'm trying to write a system to handle the errors that may occur with playfab calls.

For example when trying to LoginWithEmailAddress you can get the error

InvalidEmailOrPassword 1142.

The question is, in the unity sdk, how do I get the error code (1142).

I see .Error, .ErrorDetails, and .ErrorMessage.

I thought it might be under ErrorDetails, which has a keys section, but this returned null, so I'm guessing nothing was in there.

 

Thanks for any help provided.

sdks
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

It's in the errorCode returned. Here's an example response from Postman when getting that error:

{
  "code": 401,
  "status": "Unauthorized",
  "error": "InvalidEmailOrPassword",
  "errorCode": 1142,
  "errorMessage": "Invalid email address or password"
}

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Chris B. avatar image
Chris B. answered

In the following code, I was expecting to find error.errorCode, which doesn't seem to exist. But I figured out that error.Error is returning an enum when I looked at it, so I can just check if it's equal to PlayFabErrorCode.InvalidEmailOrPassword instead and it will do the same thing. Thanks!

 

PlayFabClientAPI.LoginWithEmailAddress(new LoginWithEmailAddressRequest
{
TitleId = playFabGameID,
Email = emailString,
Password = pwordString
}, (result) =>
{
//Handle successful login here

}, (error) =>
{
print(error.Error);

}

});
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Good catch - yes, in the Unity SDK, the error is built in the ResultContainer, which does build out the error response as (using the parameters returned in the Postman error response example above):

HttpCode = code
HttpStatus = status
Error = errorCode
ErrorMessage = errorMessage
ErrorDetails = (not in the example above, but an errorDetails can be returned for some responses)

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Roshaan avatar image
Roshaan answered

@Brendan in unity SDK when I try to debug the error.Error it prints an error message instead of error code as shown in the documentation. Can you please tell me how to get the error code in response from playfab instead of error message (string)?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Roshaan avatar image
Roshaan answered

I have found the way to get the error codes.

Edit:

Below is the sample code for doing this in Unity

private void OnFailedResponse(PlayFabError error)
{
	string message = string.Empty;

	switch (error.Error)
	{
		case PlayFabErrorCode.InvalidParams:
			message = "Invalid Parameters. Please contact support!";
		break;

                case PlayFabErrorCode.NotAuthenticated:
			message = "Player not authorized/authenticated";
                	break;

                case PlayFabErrorCode.NameNotAvailable:
                case PlayFabErrorCode.UsernameNotAvailable:
                    message = "Username or Displayname is already taken/not available";
                    break;

                default:
                    Debug.LogError(error.Error);
                    Debug.LogError(error.ErrorMessage);
                    break;
            }

            if (!string.IsNullOrEmpty(message))
            {
                Debug.LogError("Error: " + message);
                Debug.LogError("Error Report: " + error.GenerateErrorReport());
            }
        }

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tourtellotronald2020 avatar image tourtellotronald2020 commented ·

That isn't exactly the error codes. The user shouldn't have to contact support because the best detail we have for them in Invalid Parameters. That could mean the input was too long or short, the name was taken, invalid characters, all kinds of things. You shouldnt have to contact support for that. Why does invalid params have to be so general and they cant just give us the actual error code?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.