Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled exceptions occur even when having every superagent request handled #1746

Open
flareman opened this issue Oct 13, 2022 · 2 comments

Comments

@flareman
Copy link

I'm using superagent v8.0.0 to manage requests for a homebridge plugin that I have written (homebridge-caddx-interlogix). I have written a helper function to handle requests, that looks like this:

  private async makeRequest(address: string, payload = {}) {
    let response: superagent.Response = undefined;
    try {
      response = await superagent.post(address).type('form').send(payload).redirects(0);
    } catch (error: superagent.Response.error) {
      let attemptLoginFirst = false;
      if ((error.status / 100 | 0) == 3)
        attemptLoginFirst = true;
      if (attemptLoginFirst == false && Utilities.ERROR_CODES.has(error.code) == false)
        throw(error);
        await Utilities.delay(retryDelayDuration);
      if (attemptLoginFirst) {
        await this.login();
        (<any>payload)['sess'] = this.sessionID;
      }
      response = await superagent.post(address).type('form').send(payload).redirects(0);
    }

    return response;
  }

Even though all superagent.post calls are preceded by await and wrapped in try/catch blocks, I still get intermittent unhandled errors. Please bear in mind that the this.login() function also calls this same makeRequest one to actually log in to the server in question. The two issues that crop up are:

Error: socket hang up
    at connResetException (node:internal/errors:692:14)
    at Socket.socketOnEnd (node:_http_client:478:23)
    at Socket.emit (node:events:539:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

and

Error: Found
    at Request.callback (/usr/lib/node_modules/homebridge-caddx-interlogix/node_modules/superagent/src/node/index.js:900:17)
    at IncomingMessage.<anonymous> (/usr/lib/node_modules/homebridge-caddx-interlogix/node_modules/superagent/src/node/index.js:1153:18)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1358:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

All calls to superagent.post(), as well as to my helper are also prefixed with async and wrapped in try/catch blocks that manage the errors, and these exceptions stay unhandled nonetheless.

Any ideas on this? Thanks in advance :)

@vpatil-uptycs
Copy link

@flareman Did you get any solution for this?

@flareman
Copy link
Author

I ended up replacing superagent with AXIOS, which worked as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants