I have one complex function in my CloudScript and after I started to deal with error handling I came to few questions regarding proper error handling solution.
I plan to use try/catch on every server API call and if error occurs, I simply return error statement and go out of function. The problem is that I have two main server calls in my function - GrantItemsToUsers (called just once) and AddUserVirtualCurrency (called X-times depending on the number of currencies added). My questions follows:
1) I presume that parameters to server calls are ok. In that case, what else can possibly go wrong during server call which consequently leads to error?
2) Let´s say that GrantItemsToUsers works ok and some of the items are granted to the player, but during the call of AddUserVirtualCurrency something goes wrong and the method fails. Then I need to rollback changes I made with item grants - is there some better technique than remembering granted items ID´s and calling RevokeInventoryItem on each of them?
3) Is it even necessary and common to implement these rollbacks? I presume that my code works fine and then it should fail only if there are some general server problems. But in that case I presume that other server calls will not work too, so no changes will be made to DB and/or I won´t be able to revoke items with API call, so is there a point to have some rollback code? Generally, writing rollbacks means a lot more code than I have right now (for example, granted items are bundles, so I need to get bundled items ID´s, also if some of the currency add fails I need to rollback all previously added currencies within this call... and these "service functions" will grow with more and more code) and that leads me to question if I am on the good way and if there are some best practices with error handling dealing.
Thanks in advance for your answers!