Skip to content

Support for customizable client-side timeout in addition to server-side timeout #1260

@zwa73

Description

@zwa73

While using the package for long-polling scenarios, I've noticed a limitation when dealing with network instability.
Specifically, the timeout parameter in request is tied directly to server-side timeout behavior.

When using @cypress/request-promise within a function that sends requests, I observed that the timeout parameter is primarily passed as part of the data payload to the API (options.form.timeout).

While this successfully controls server-side timeout in the API (e.g., the Telegram API), there seems to be no clear way to enforce a client-side timeout for the network request itself.

I would like to request the ability to define client-side timeouts independently, to ensure requests don't hang indefinitely due to network issues or server-side delays.

And for the current implementation

_request(_path, options = {}) {
    if (!this.token) {
      return Promise.reject(new errors.FatalError('Telegram Bot Token not provided!'));
    }

    if (this.options.request) {
      Object.assign(options, this.options.request);
    }

    if (options.form) {
      this._fixReplyMarkup(options.form);
      this._fixEntitiesField(options.form);
      this._fixReplyParameters(options.form);
    }
    if (options.qs) {
      this._fixReplyMarkup(options.qs);
      this._fixReplyParameters(options.qs);
    }

    options.method = 'POST';
    options.url = this._buildURL(_path);
    options.simple = false;
    options.resolveWithFullResponse = true;
    options.forever = true;
    debug('HTTP request: %j', options);
    return request(options)
      .then(resp => {
        let data;
        try {
          data = resp.body = JSON.parse(resp.body);
        } catch (err) {
          throw new errors.ParseError(`Error parsing response: ${resp.body}`, resp);
        }

        if (data.ok) {
          return data.result;
        }

        throw new errors.TelegramError(`${data.error_code} ${data.description}`, resp);
      }).catch(error => {
        // TODO: why can't we do `error instanceof errors.BaseError`?
        if (error.response) throw error;
        throw new errors.FatalError(error);
      });
  }

Can I directly set a value on options.timeout as a temporary workaround?

like

if(_path=="getUpdates"){
	options.timeout = options.form.timeout*1000 + 5000;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions