Skip to main content
Version: SDK-5.11.4

Common Error Handling Example

The following is an example of handling errors that occur frequently in BACKND.
If problems occur in your game, show a pop-up, move the user to the login screen, or allow users to manually recall methods while ensuring the means fit your game logic.

Example

    public void GetData(int maxRepeatCount)
{
if(maxRepeatCount <= 0)
{
//Game error occurs
return;
}

Backend.GameData.Get("score", new Where(), callback =>
{
if(callback.IsSuccess())
{

}
else
{
if(callback.IsClientRequestFailError()) // The client is temporarily disconnected from the network
{
GetData(maxRepeatCount - 1);
}
else if(callback.IsServerError()) // The server encountered an error
{
GetData(maxRepeatCount - 1);
}
else if(callback.IsMaintenanceError()) // The server status is 'maintenance'
{
//Sends to maintenance pop-up + login screen
Debug.Log("The game is under maintenance.");
return;
}
else if(callback.IsTooManyRequestError()) // When 403 Forbbiden error occurs because too many requests are sent in a short time
{
//This occurs when too many requests are sent in a short time. BACKND's method request has to be stopped for 5 minutes.
return;
}
else if(callback.IsBadAccessTokenError())
{
bool isRefreshSuccess = RefreshTheBackendToken(3); // Refreshes up to 3 times

if(isRefreshSuccess)
{
GetData(maxRepeatCount - 1);
}
else
{
}
}
}
});
}

//The synchronous process is recommended for the refresh token as it is an important method related to the login feature
bool RefreshTheBackendToken(int maxRepeatCount)
{
if(maxRepeatCount <= 0)
{
return false;
}
var callback = Backend.BMember.RefreshTheBackendToken();
if(callback.IsSuccess())
{
return true;
}
else
{
if(callback.IsClientRequestFailError()) // The client is temporarily disconnected from the network
{
return RefreshTheBackendToken(maxRepeatCount - 1);
}
else if(callback.IsServerError()) // The server encountered an error
{
return RefreshTheBackendToken(maxRepeatCount - 1);
}
else if(callback.IsMaintenanceError()) // The server status is 'maintenance'
{
//Sends to maintenance pop-up + login screen
return false;
}
else if(callback.IsTooManyRequestError()) // When 403 Forbbiden error occurs because too many requests are sent in a short time
{
//Too many requests are being sent
return false;
}
else
{
//If the access token cannot be re-issued even upon retry,
//you must log in manually with custom login or federation sign-in.
//In the case of a duplicate login, a 401 bad refreshToken error may also occur.
Debug.Log("There was a problem connecting to the game. Returning to the login screen.\n" + callback.ToString());
return false;
}
}
}