RiotSharp icon indicating copy to clipboard operation
RiotSharp copied to clipboard

api.Spectator.GetCurrentGameAsync throws an exception

Open PatriQ94 opened this issue 5 years ago • 9 comments

Why does await api.Spectator.GetCurrentGameAsync throw an exception if the player is not in a game? It should either return the correct CurrentGame with populated data or return null.

PatriQ94 avatar Jan 31 '20 21:01 PatriQ94

Okay so upon further testing of this function I can confidently say that it doesn't work properly when a summoner leaves a match.

Here's the code that I used https://pastebin.com/eCPQzsFB How its supposted to work: It checks every 5 seconds if a player entered a match, prints outs a message, then keeps checking until the player left the match, then prints a message.

How it behaves: It prints out a message when user entered a match, but when player leaves a match, the GetCurrentGameAsync sometimes throws an exception, sometimes it returns data of an already ended match and it's doing so for a few minutes after the player already left the match.

PatriQ94 avatar Jan 31 '20 21:01 PatriQ94

Is this issue based on RiotApi or RiotSharp?

xXLAOKOONXx avatar Jan 31 '20 23:01 xXLAOKOONXx

Is this issue based on RiotApi or RiotSharp?

RiotApi is a class within RiotSharp, so not sure exactly what you're asking. There's the exact code so you can check it out.

PatriQ94 avatar Jan 31 '20 23:01 PatriQ94

It's a question of whether this is an issue with Riot Game's API (https://developer.riotgames.com/) or RiotSharp. The API returns a 404 when the summoner is not in the game, so RiotSharp throws an error for that (I believe). (It doesn't necessarily have to behave this way).

If you're getting data back after a match ended, that is going to be 100% on Riot's API end. RiotSharp just handles requests to the API and returns whatever the API gave back.

MingweiSamuel avatar Jan 31 '20 23:01 MingweiSamuel

It's a question of whether this is an issue with Riot Game's API (https://developer.riotgames.com/) or RiotSharp. The API returns a 404 when the summoner is not in the game, so RiotSharp throws an error for that (I believe). (It doesn't necessarily have to behave this way).

I see, yeah makes sense. It's unfortunate that it throws error with "404 - Data not found" tho instead of simply returning null.

If you're getting data back after a match ended, that is going to be 100% on Riot's API end. RiotSharp just handles requests to the API and returns whatever the API gave back.

I'll do some more testing and contact Riot then.

PatriQ94 avatar Feb 01 '20 00:02 PatriQ94

I'm fairly sure, that returning a 404 error is the intended behavior, when the summoner isn't in a game.

JanOuborny avatar Feb 01 '20 00:02 JanOuborny

One could argue 404 is null in http

xXLAOKOONXx avatar Feb 01 '20 00:02 xXLAOKOONXx

I would argue 204 is more like null than 404 is, but Riot's API doesn't give 204s unfortunately

MingweiSamuel avatar Feb 01 '20 01:02 MingweiSamuel

Okay so I've contacted Riot and asked about this issue - why is their endpoint /lol/spectator/v4/active-games/by-summoner/{encryptedSummonerId} API returning random data (sometimes old data, sometimes an 404 exception). Keep in mind that this endpoint is connected to the problem I'm having with function GetCurrentGameAsync. So it looks like their distributed systems don't update caches fast enough and when I'm calling GetCurrentGameAsync I hit different servers, therefore getting random answers. They have also suggested to not call it more than once per minute or so, so their caches get updated.

PatriQ94 avatar Feb 01 '20 22:02 PatriQ94