Testing and Debugging
Local Testing
When testing in a local environment, the SDK will initialize in debug mode. This gives access to all APIs and allows you to test your integration without having to upload your game to the Wortal.
Most APIs will return mock data, but player.setDataAsync
and player.getDataAsync
will save and load
the data to and from local storage. This allows you to test your data saving and loading logic and
ensure that it works as expected.
Error Handling
The SDK will return an ErrorMessage object when an error occurs. This object contains important information about the error, including the error code, error message, calling function the error was thrown from, and a URL to the relevant API docs.
It's good practice to catch and handle errors in your code. This will help you identify and fix issues when they arise.
All APIs with the Async
suffix return a promise that can be used to catch errors. You can check the error code
to determine how to properly handle the error.
Wortal.context.inviteAsync(payload).then(() => {
// Invite sent successfully
}).catch((error) => {
if (error.code === "NOT_SUPPORTED") {
// Invite is not supported on this platform.
// You can continue gameplay without inviting.
} else if (error.code === "NETWORK_FAILURE") {
// The player has lost their internet connection.
// You can retry the invite when the player reconnects.
} else {
// Gracefully recover and continue gameplay if possible.
}
});
Debugging
The SDK will log debug messages to the console on every platform. Enabling debug level logging will give you more information about what the SDK is doing and help you identify and fix issues when they arise.
API Support
Not all APIs are supported on all platforms. There are two main methods to handling unsupported APIs:
- Catch the
NOT_SUPPORTED
error thrown when calling an unsupported API.
Wortal.context.inviteAsync(payload).catch((error) => {
if (error.code === "NOT_SUPPORTED") {
// Invite is not supported on this platform.
// You can continue gameplay without inviting.
return;
} else {
// Gracefully recover and continue gameplay if possible.
}
});
- Check if the API is supported on the current platform before calling it.
const supportedAPIs = Wortal.getSupportedAPIs();
if (supportedAPIs.includes("context.inviteAsync")) {
// Invite is supported on this platform.
}
Either approach is acceptable, but the first method is recommended as it puts more focus on proper error handling and is less prone to error than the second method due its reliance on string lookups.