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 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.
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.