I get this error message in Cloud Script and the rest of the code in the function GrantLeaderboardRewardsToAllPlayersFourthPart is not executed because of this error:
{ "Message": "PlayFab API request error", "Level": "Error", "Data": { "request": { "Message": "28/02/2020 Leaderboard 1 Results Get the fantastic Bamboo Sword!", "Recipient": "989FAED7FD9ABBB2" }, "api": "/Server/SendPushNotification", "apiError": { "errorDetails": null, "errorMessage": "PushNotEnabledForAccount", "errorHash": null, "errorCode": 1094, "status": "BadRequest", "error": "PushNotEnabledForAccount", "code": 400 }, "result": null } }
handlers.GrantLeaderboardRewardsToAllPlayersFourthPart = function (args, context) { var notificationsend = false; var sendmessage = "test"; var result = SendPushNotificationMessage(sendmessage); if (result == true) notificationsend = true; else notificationsend = false; log.info("notificationsend: " + notificationsend); var resultevent = server.WritePlayerEvent({ PlayFabId: currentPlayerId, EventName: "GrantLeaderboardRewardsToAllPlayersFourthPart_Finished", Body: { "PlayFabID": currentPlayerId, "NotificationSend": notificationsend, "Sendmessage": sendmessage } }); if (resultevent.Error == null) log.info("Writing GrantLeaderboardRewardsToAllPlayersFourthPart_Finished event successful."); else log.info("Writing GrantLeaderboardRewardsToAllPlayersFourthPart_Finished event not successful."); return; } function SendPushNotificationMessage(message) { log.info("PushMessage: " + message); var result = server.SendPushNotification({ Recipient: currentPlayerId, Message: message }); if ((result != null) && (result.Error == null)) return true; else return false; }
The function GrantLeaderboardRewardsToAllPlayersFourthPart is only triggered by a rule.
What can I do if a player has not yet enabled push notifications in his account? I want to continue executing the rest of the code in GrantLeaderboardRewardsToAllPlayersFourthPart.
I don't want that my entire function fails because there is some code after var result = SendPushNotificationMessage(sendmessage); that needs to be executed, even if it is not possible to send the push notification to the player. I just want to set notificationsend = false; if it is not possible to send the push notification and I want to log the error code so that I can store it with API server.WritePlayerEvent.
How can I avoid that my cloud script code fails?