Skip to main content

Error Handling

By default Kalamba SDK Wrapper handles RGS errors and triggers error popup with proper error message. If you want to handle errors manually, you can send showErrors: false in sdk.configure. If you want to use error popup delivered by Kalamba SDK Wrapper but you want to handle some errors manually you can configure sdk by sending skipErrors: ['ERROR_CODE_1', 'ERROR_CODE_2']. In that case wrapper will not trigger error popup for ERROR_CODE_1 and ERROR_CODE_2 and you must do it manually if you want to show error popup.

Open Game

import { RgsError, RgsErrorCode, TimeoutError } from '@kalamba/sdk'

try {
const openGameResponse = await sdk.openGame()
} catch (e) {
if (e instanceof TimeoutError) {
// Do something on timeout
} else if (e instanceof RgsError) {
if (e.data.code === RgsErrorCode.ALREADY_LOGGED_IN) {
// Do something on ALREADY_LOGGED_IN error
}
// Do something generic on open game error
} else {
// Do something on unexpected error
}
}

Play

import { RgsError, RgsErrorCode, TimeoutError } from '@kalamba/sdk'

try {
const playResponse = await sdk.play(playPayload)
} catch (e) {
if (e instanceof TimeoutError) {
// Do something on timeout
} else if (e instanceof RgsError) {
if (e.data.code === RgsErrorCode.UNFINISHED_ROUND_IN_PROGRESS) {
// Do something on UNFINISHED_ROUND_IN_PROGRESS error
}
// Do something generic on play error
} else {
// Do something on unexpected error
}
}

Informing wrapper about some game client error

sdk.send('error', {
messageKey: 'WebGL_unsupported',
messageCode: 'WEBGL_UNSUPPORTED',
type: 'CLOSE',
})

It will trigger error popup on wrapper. Wrapper will retrieve message for error popup component by translating key messageKey for current language. One can provide custom translations.

It is also possible to send message directly.

sdk.send('error', {
message: "We're sorry, but it appears that WebGL is not enabled in your browser.",
messageCode: 'WEBGL_UNSUPPORTED',
type: 'CLOSE',
})

It will trigger error popup on wrapper. Message is passed directly to the error popup component.

Error catalog

Every RGS error carries a code (RgsErrorCode) and is mapped by the wrapper to a default action, which determines the button shown on the error popup:

  • CLOSE — the player can only close the game.
  • RELOAD — the player can reload the game and try again.
  • CONTINUE — the error is recoverable, the player can dismiss the popup and continue playing.
CodeActionDescription
CONNECTION_ERRORRELOADConnection to the RGS failed.
INVALID_BET_CURRENCYCLOSEBet was placed in a currency not valid for the session.
INVALID_BETCONTINUEBet is not one of the legal bets.
INVALID_CAGE_CODECLOSEInvalid operator (cage) code.
INVALID_CLIENT_TYPECLOSEClient type is not accepted by the RGS.
INVALID_MESSAGE_FORMATCLOSERequest message was malformed.
INVALID_SESSIONCLOSESession is invalid or has expired.
TOO_HIGH_BET_FREQUENCYCONTINUEBets were sent too frequently.
TOO_HIGH_ACTION_FREQUENCYCONTINUEActions were sent too frequently.
USER_LOCK_INVALID_PARAMSCLOSEInvalid parameters while locking the user.
USER_ALREADY_LOCKEDCLOSEUser is already locked.
GAME_SERVER_ERRORRELOADInternal game server error.
SESSION_MANAGEMENT_ERRORRELOADSession management failure on the RGS side.
MESSAGE_SENDER_ERRORRELOADInternal RGS messaging failure.
FREE_ROUNDS_PROCESSING_ERRORRELOADFree rounds request could not be processed.
WEB_SESSION_NOT_OPENRELOADWeb session is not open.
GAMING_LIMITS_REACHEDCLOSEPlayer's gaming limits have been reached.
GAMING_LIMITS_REACHED_BETCONTINUEBet was rejected because it would exceed gaming limits.
OUT_OF_MONEYCONTINUEPlayer's balance is insufficient for the bet.
UNFINISHED_ROUND_IN_PROGRESSCLOSEAn unfinished round is still in progress.
ACCESS_DENIEDCLOSEAccess to the requested resource was denied.
CREDENTIALS_NOT_FOUNDCLOSECredentials could not be found.
ALREADY_LOGGED_INCLOSEUser is already logged in.
GAME_UNAVAILABLECLOSEGame is not available.
BONUS_RESTRICTIONCLOSEAction is restricted by bonus terms.
TOO_MANY_OPEN_GAMESCLOSEToo many games are open at the same time.
GAME_FROZENCLOSEGame has been frozen.
WALLET_PROCESSING_ERRORCLOSEWallet transaction could not be processed.
FORCED_OUTCOMES_NOT_ALLOWEDCONTINUEForced outcomes are not allowed in this environment.
MISSING_GAME_STATERELOADGame state is missing on the RGS side.
DATA_ACCESS_ERRORRELOADRGS failed to access its data store.
UNKNOWNCLOSEUnrecognized error.
TIMEOUTRELOADPseudo-code: the RGS did not respond in time (TimeoutError on the Game Client side).

TIMEOUT is not a member of RgsErrorCode — it is reported when a request times out. It can be skipped like any other code via skipErrors: ['TIMEOUT'].

Translation keys

The wrapper resolves the error popup message by translating a key derived from the error:

  • RGS errors use RgsError.<CODE>, e.g. RgsError.OUT_OF_MONEY.
  • Timeouts use Error.TIMEOUT.

The Game Client MAY override these messages by sending custom translations:

sdk.send('translations', {
Error: {
TIMEOUT: 'The server took too long to respond.',
},
RgsError: {
OUT_OF_MONEY: 'You are out of credits.',
},
})