Properly handling exceptions and cancelling Tasks

Hi there,
I’d like to know the proper way to handle Nakama exceptions.

For example, when I try to join with a empty Match ID string using JoinMatchAsync, I get this error in the Unity console:
WebSocketException: No match ID or token found

However, I can’t figure out which class is outputting the error so I can’t properly handle it. I also tried listening to the ISocket.ReceivedError event, but did not receive any events.

Do you have suggestions on how to handle these type of exceptions?

Also, how would you suggest cancelling the JoinMatchAsync method? I would normally pass in a cancellation token to the task and returning the method at certain points in the logic, but since the JoinMatchAsync method is in a DLL, I can’t implement it. What would you suggest? (for example, if a user clicks on join match several times, I’d like to cancel each task before starting a new one)

thanks!

Hi @david. You’re right we should add support for cancellation tokens to functions in the SDK. I would say that in your specific case you could disable the button click after a request has been sent rather than use a cancellation token to cancel the current request to substitute it for the new one.

In any case I think the use case is valid. Please open an issue on the tracker for our .NET client sdk and we can schedule it into a dev sprint. If you’re feeling adventurous we’d be happy to review a pull request for it as well.