Closed mattbadley closed 6 years ago
Hello,
Does PlayFabError extends System.Exception? If yes, then I think you should be able to use it. If not, maybe you need to create your own class that extends System.Exception and contains a PlayFabError variable?
In theory we could support rejecting promises with objects other than exceptions but it was originally designed like that because .Then( ... ).Catch(ex => ... )
is meant to roughly model a regular try { ... } catch (Exception ex) { ... }
block.
In Javascript promises you can reject a promise with any object, which makes sense because you can also throw any object. In C# however, you can only use the throw
keyword with an exception. For now I'd recommend making your own custom exception type that extends System.Exception and can wrap up a PlayFabError.
In response to your formatting question, it's really up to you what style you think looks best. I usually split function arguments onto separate lines if the line is more than around 80-90 characters. You probably also can leave out the type declaration for the lambda function:
PlayFabClientAPI.LoginWithIOSDeviceID(
request,
result => promise.Resolve(result),
error => promise.Reject(new System.Exception())
);
Thanks for the comments - wrapping the PlayFabError in my own custom class was a good solution and works well!
I'm trying to integrate this library with PlayFab (a cloud based games backend). I have it working except for the error side of things.
Here's some code:
I then setup the promise chain in the following way -
The problem is with promise.Reject. I can only pass in an object which is of type System.Exception... but Playfab returns errors of type PlayFabError.
How can I set this up to use PlayFabError objects?
Also I've put the lambda functions inline (the success and fail callbacks), but this doesn't feel right. Is there a better way to format this?
Any help would be appreciated!