On a C# rest server, when a user tries to cancel a matchmaking ticket, I make the following call from the server:
var response = await _gameLiftClient.StopMatchmakingAsync(stopRequest, cancellationToken);
This works most of the time and all is fine. However, if this request is sent at exactly the time the ticket moved to Completed or Placing states, this will throw an InvalidRequestException, saying something like “Matchmaking ticket is in PLACING status and cannot be canceled.”.
I imagine that the desired flow would be that I first call _gameLiftClient.DescribeMatchmaking, and then if its still searching, cancel it, however since in the world of the internet all is async, even if I do that there is no guarantee that when I call “StopMatchmakingAsync” it wont have moved to an invalid state anyway.
So for now what I am doing is parsing the exception Message to check like… “does the exception message have the word “PLACING” in it? what about COMPLETED?” because in those cases, what I will do is basically nothing, it was too late to cancel the ticket, so the user will go into the match anyway.
The reason I am posting here is that this is terrible coding… unmaintainable… if tomorrow you guys decide to change the message of the exception, my server will have the same bug again… so is there any better way to do this that I am not seeing? Or, if not, could you please, from the “StopMatchmakingAsync”, instead of throwing an exception just return a result that allows us to elegantly deal with the result?