xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.18k stars 372 forks source link

iqCaller.request or iqCaller.get UnhandledPromiseRejectionWarning: TimeoutError #868

Closed ishankaru closed 3 years ago

ishankaru commented 3 years ago

node v12.18.0 @xmpp/client v0.11.1

When I run my code I am getting the result iq in the stanza event immediately. But the iqCaller hangs on the called line for the timeout duration and displays the error below. I am testing this way to get error free results, so the final code will be more organized once I figure out the problem.

Everything is connecting and working fine otherwise and getting the expected stanzas returned etc.

(node:22704) UnhandledPromiseRejectionWarning: TimeoutError
    at C:\node\project\node_modules\@xmpp\events\lib\timeout.js:17:13
    at async IQCaller.request (C:\node\project\node_modules\@xmpp\iq\caller.js:54:7)
    at async xmppClient (C:\node\project\server.js:35:18)
(node:22704) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:22704) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Project code skeleton:

const { client, xml, jid } = require("@xmpp/client");
const debug = require("@xmpp/debug");
const { json } = require("body-parser");
var parser = require("xml2json");

const xmppClient = async function () {

  const xmpp = client({
    service: service,
    username: roomNick,
    domain: domain,
    password: password,
    resource: resource,
  });

  const { iqCaller } = xmpp;

  xmpp.on("error", (err) => {
    console.error(err);
  });

  address = await xmpp.start().catch(console.error);

  let response = await iqCaller.get(xml("query", { xmlns: "jabber:iq:profile" }, xml("command", {}, content)), to, 2 * 1000);
  console.log(response);
};

xmppClient();

*** Guess I will add a try/cache around my call!