grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.17k stars 110 forks source link

feat: add a warning in debug mode upon "Call to 'getMe' failed! (401: Unauthorized)" that the bot token is incorrect #561

Closed janek closed 4 months ago

janek commented 5 months ago

hi!

I'm trying to deploy my bot and starting with following examples in the docs. I get to the same error in 2-3 ways:

Here's a copy-paste of the error from my local attempt with Docker:

docker run --env-file .env dockerdeno

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Task start deno run --allow-net --allow-env main.ts
error: Uncaught (in promise) GrammyError: Call to 'getMe' failed! (401: Unauthorized)
    return new GrammyError(
           ^
    at toGrammyError (https://deno.land/x/grammy@v1.22.4/core/error.ts:43:12)
    at ApiClient.callApi (https://deno.land/x/grammy@v1.22.4/core/client.ts:328:20)
    at async withRetries (https://deno.land/x/grammy@v1.22.4/bot.ts:660:41)
    at async Bot.init (https://deno.land/x/grammy@v1.22.4/bot.ts:307:22)
    at async Promise.all (index 0)
    at async Bot.start (https://deno.land/x/grammy@v1.22.4/bot.ts:439:9)
rojvv commented 5 months ago

Closing per https://t.me/grammyjs/229944.

janek commented 5 months ago

In my case the token was invalid because I accidentally appended a letter. It would have been ideal to get a "Token might be invalid" suggestion in the error, but I should have also figured it out from the 401.

KnorpelSenf commented 5 months ago

This is already documented at https://grammy.dev/resources/faq#_401-unauthorized

janek commented 4 months ago

@KnorpelSenf agreed, and I missed that - but what I meant now is in code. If it's clear that 401 means error is on the side of the user and token is invalid, then it would be safe and very helpful to put that in the error message (to make it more informative).

KnorpelSenf commented 4 months ago

That's a really good idea actually

janek commented 4 months ago

Nice, I'm glad you like it!

KnorpelSenf commented 4 months ago

Please review #574 and approve it if these changes work for you

janek commented 3 months ago

Thank you for adding and merging this, and listing me in contributors! 💟 That's so nice.

I'm sorry I didn't answer sooner, I don't check my GitHub notifications often enough

KnorpelSenf commented 3 months ago

You're welcome :) No worries!

You can enable email notifications so you don't have to check manually