gramio: Error when fetching updates

Error received when fetching updates TypeError: fetch failed
    at node:internal/deps/undici/undici:13502:13
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Bot._callApi (/app/node_modules/gramio/dist/index.cjs:557:22)
    at async suppressError (/app/node_modules/gramio/dist/utils-CYIya32k.cjs:64:13)
    at async Object.withRetries (/app/node_modules/gramio/dist/utils-CYIya32k.cjs:70:31)
    at async Updates.startFetchLoop (/app/node_modules/gramio/dist/index.cjs:356:25) {
  [cause]: Error: connect EHOSTUNREACH 149.154.167.220:443
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1611:16) {
    errno: -113,
    code: 'EHOSTUNREACH',
    syscall: 'connect',
    address: '149.154.167.220',
    port: 443
  }
}

I get this error at least 4/5 times a day. The bot still continues to work without interruption. It is hosted on an aws VPS.

Is there a way to solve this error?

The code of my bot can be viewed here: Aztec Bot

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Ok now it works perfectly! Thanks again and sorry, but I didn’t quite understand how to implement it!

Yeah we should cover more cases in the documentation Feel free to ask anything

async startServer(bot: Bot): Promise<Server> {
    // Setup Middleware
    this.app.use(express.json());
    this.app.use((req: Request, res: Response, next: NextFunction) => {
      // logger.info(
      //   `${req.method} ${req.url} ${JSON.stringify(req.body, null, 2)}`
      // );
      logger.info(req.headers);
      next();
    });

    // Setup Webhook route
    this.app.post(
      `/${this.WEBHOOK_PATH}`,
      webhookHandler(bot, "express", "TEST_TOKEN")
    );

    // Start server
    const server = this.app.listen(this.PORT, () => {
      logger.info(`## Server listening on port ${this.PORT} [WEBHOOK MODE] ##`);
    });

    return server;
  }
[30-06-2025 20:45:32] INFO (167045):
    host: "1386-151-27-204-154.ngrok-free.app"
    content-length: "397"
    accept-encoding: "gzip, deflate"
    content-type: "application/json"
    x-forwarded-host: "1386-151-27-204-154.ngrok-free.app"
    x-forwarded-proto: "https"

It doesn’t seem to work, I don’t get the token back. In the headers there is no “X-Telegram-Bot-Api-Secret-Token”. Also the command is not handled and therefore I do not receive any response from bots in the Telegram chat.

PS: Of course if I remove “TEST_TOKEN” everything works perfectly.

You should also put your token at the bot.start method or directly call setWebhook method

webhookHandler is just receiver

Gotcha! Thanks again!

also maybe telegraf just ignore this issue when it happends

https://github.com/telegraf/telegraf/blob/0638cf4cc7ba8467ccb9222726024c99c54d119f/src/core/network/polling.ts#L74

Yea they notice about errors only in DEBUG=telegraf:* mode

I can also make it configurable but in my opinion it is important to show this errors to developer

What do you think about this?