TwitchLib / TwitchLib.Api

API component of TwitchLib.
70 stars 84 forks source link

TwitchHttpClient can have a more accurate message #210

Open JDR-Ninja opened 3 years ago

JDR-Ninja commented 3 years ago

Hello, The method TwitchLib.Api.Core.HttpCallHandlers.TwitchHttpClient.HandleWebException throw a BadTokenException when the api return 403. But in some case, the returned message from the api is : { "error": "Forbidden", "status": 403, "message": "channel points are not available for the broadcaster" } But TwitchHttpClient will hide this information and return a bad token message. I tested this issue with my account (new twitch account) and called "Helix.ChannelPoints.GetCustomReward". I searched for a long time before realizing that my token was correct, but the problem was that my channel did not support the functionality.

Syzuna commented 3 years ago

Yes we know this is not ideal but the library pre dates Helix and its standard error messages and back then we only had Status codes to work with. Changing it would be a big change and most likely also would cause a lot of hacked together code.. so I guess this wont be done until v5 is removed and we got time to rewrite the library completely (sth we are planning for some time now). Sorry :/

Syzuna commented 1 year ago

While it isnt ideal it is at least sth. With 3.9.0 you can now do:

            try
            {
               // API call
            }
            catch (HttpResponseException e)
            {
                Console.WriteLine(await e.HttpResponse.Content.ReadAsStringAsync());
            }
Felk commented 1 year ago

With a bunch of chat functionality being moved over to Helix, I suspect this will trip quite a few more people now. For example, when whispering a user Twitch might return a status code 403 with the message

The recipient's settings prevent this sender from whispering them

but TwitchLib outputs this error, which can misguide people quite badly:

TwitchLib.Api.Core.Exceptions.BadTokenException: The token provided in the request did not match the associated user. Make sure the token you're using is from the resource owner (streamer? viewer?)

Would it be acceptable to generify the error message a bit? I believe a less helpful message would be better than a misleading one.