Closed tuscen closed 6 years ago
https://github.com/TelegramBots/Telegram.Bot/blob/ed21285554ea3720cc70fcd8298e4cc2eeededbb/src/Telegram.Bot/TelegramBotClient.cs#L270-L285
GetMeAsync()
will throw ApiRequestException("Invalid token", 401)
here https://github.com/TelegramBots/Telegram.Bot/blob/ed21285554ea3720cc70fcd8298e4cc2eeededbb/src/Telegram.Bot/TelegramBotClient.cs#L243-L245
@tuscen @pouladpld I did some discovery:
Should_Fail_Test_Api_Token
test is unreliable. Replacing bot token "0:1this_is_an-invalid-token_for_tests"
with the one provided in Telegram Bot API examples 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
(or changing few characters in real bot token, same result will be for revoked token i guess) breaks the test - it fails because MakeRequestAsync
trows new ApiRequestException("Invalid token", 401)
https://github.com/TelegramBots/Telegram.Bot/blob/ed21285554ea3720cc70fcd8298e4cc2eeededbb/test/Telegram.Bot.Tests.Integ/Getting%20Updates/GettingUpdatesTests.cs#L33-L43Regex.IsMatch(token, @"^\d*:[\w\d-_]{35}$")
is incorrect -
should be escaped, and second - there is no actual token specification provided in official Telegram Bot API documentation. I think we should leave this check to Telegram.@karb0f0s Valid point. Token form is not specified anywhere so it shouldn't be present in the library. In this case catching 404 will be valid in TestApiAsync
.
Wrapping up our discussion:
ApiRequestException
should return actual error message instead of "Invalid token" to help users to understand what's actually going on. Telegram API does not provide Invalid token
error.404 HttpRequestError
could be thrown only in case of malformed API request string - either token format is totally incorrect (for example calling TelegramBotClient("put_your_token_here")
) or making a request to nonexisting API method. This error should not be caught to inform user that something really goes wrong.
Bot API returns 404 on incorrectly formatted tokens. And since
TelegramBotClient
can't be instantiated with incorrectly formatted tokenMakeRequestAsync
will throw401 Invalid Token
. So catching 404 doesn't make sense here.