Reputation: 1
I am trying to use JS PlayFab SDK on Cocos Creator 3.8 to login user with custom ID. The problem is when there is an error sent back from server, it always show "Unhandled Rejection" which I always use try catch block to catch the error.
Uncaught In Promise More Details
MenuManager.ts
private async checkLoginStatus() {
try {
await MyPlayFabManager.instance.checkLogin();
const nameLabel = this.profile.getChildByPath("Info/Name").getComponent(Label);
nameLabel.string = MyPlayFabManager.instance.displayName;
this.checkUserInfo();
} catch (e) {
console.error("Error in checkLoginStatus: ", e);
this.showLoginMenu();
}
}
MyPlayFabManager.ts
public async checkLogin() {
this.customId = sys.localStorage.getItem("custom_id");
this._email = sys.localStorage.getItem("x-game-email");
this._password = sys.localStorage.getItem("x-game-pass");
return new Promise<void>(async (resolve, reject) => {
try {
if (this._email && this._password) {
console.log("Logging in with email and password");
await this.loginWithEmail(this.decryptData(this._email), this.decryptData(this._password));
resolve();
} else if (this.customId) {
console.log("Logging in as guest");
await this.loginAsGuest();
await this.getAccountInfo();
resolve();
} else {
console.log("No login credentials found");
throw new Error("No login credentials found");
}
} catch (e) {
console.error("Error in checkLogin: ", e);
reject(e);
}
});
}
public async loginAsGuest() {
return new Promise<void>((resolve, reject) => {
PlayFabClientSDK.LoginWithCustomID(
{
TitleId: "XXXXX",
CustomId: this.customId,
CreateAccount: false,
},
async (result, error) => {
if (result) {
console.log("Login success: ", result);
this.playfabId = result.data.PlayFabId;
this.isGuest = true;
resolve();
} else {
console.error("Login failed: ", error);
reject(error);
}
}
);
});
}
I am using PlayFab JavaScriptSDK version 1.175 (Latest) and Cocos Creator v3.8.
Thanks for any help.
I want it to catch the error and don't show the on browser screen like this
Upvotes: 0
Views: 29