Skip to main content

Error handling

Every QSPlaySDK.* method returns a Promise. When something goes wrong, the promise rejects with an SdkError object — an ordinary error (Error) with an additional code field:

interface SdkError extends Error {
readonly code: string;
}

Branch your handling on error.code, not on the text of error.message — the message is meant for logs and debugging, not for programmatic checks:

try {
await QSPlaySDK.user.getUserToken();
} catch (error) {
switch (error.code) {
case "USER_NOT_AUTHENTICATED":
// show user.showAuthPrompt()
break;
case "TIMEOUT":
// the portal didn't respond — retry later or tell the player about a network problem
break;
default:
// react to an unexpected code the same way as to TIMEOUT/UNKNOWN
break;
}
}

Error codes​

CodeWhen it occurs
TIMEOUTThe portal didn't respond to a request within 10 seconds — for example, the portal tab was closed or froze.
UNSUPPORTED_METHODThe called method isn't supported by the current version of the portal.
USER_NOT_AUTHENTICATEDuser.getUserToken() was called while nobody is signed in to the portal account.
DATA_QUOTA_EXCEEDEDdata.setItem()/data.clear() would exceed the 1 MB per-player-per-game limit.
UNKNOWNAn unexpected error on the portal's side.

USER_NOT_AUTHENTICATED and DATA_QUOTA_EXCEEDED are expected, "business" errors: handle them explicitly in the places where you call the corresponding methods. TIMEOUT and UNKNOWN signal that the request failed for a reason beyond the game's control; a general handler (retrying the request, telling the player) is enough for them, without distinguishing each specific method.