0

I am trying to make a http post request to a remote server. It is successfully requested and get expected response in local development. However, after being promoted to DEV and UAT servers the same request posted an issue:

Encountered error in Axio request: read ECONNRESET

Here is the stack:

Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20)
    at TLSWrap.callbackTrampoline (internal/async_hooks.js:131:17)

Here is the code:

async login(): Promise<string | undefined> {
    try {
      const result = await lastValueFrom(
        this.httpService.post(
          `${this.apiUrl}/login`,
          {
            email: this.configService.get('EMAIL'),
            password: this.configService.get('PASSWORD'),
          },
          {
            headers: {
              'Content-Type': 'application/json',
            },
          },
        ),
      );

      this.logger.log(
        `[login] result: ${result}`,
      );

      return result.data.token;
    } catch (error) {
      this.logger.error('can not login');
      this.logger.error(error);
    }
  }

I asked network and security team to whitelist all the related URLs but the issue still persists. And I couldn't find any good sources to better explain and understand the issue. So I want to ask what can be the cause of this problem? Is it from my end or the web infrastructure end that can be the blocker here?

ThavinV
  • 3
  • 3
  • It's very unlikely the problem has anything to do with this code. First thing I'd do is compare your runtime environments. Is this running in Node.js? If so, what are your local and remote (DEV and UAT) versions? – Phil Jul 12 '23 at 04:36
  • @Phil yes, it is running in Nodejs. My `package.json` mentions this for nodejs: `"engines": { "node": ">=14.17.6", "yarn": ">=1.22.5" }` and dockerfile for the image is `node:14.17.6-alpine3.14` – ThavinV Jul 12 '23 at 09:42
  • Yes, but what version of Node.js are you _actually_ running? Support for v14 ended 30th April 2023. I would highly recommend updating that deployment image to at least v18 – Phil Jul 12 '23 at 10:43
  • @Phil I'm running Nodejs v14.17.6 in my local machine – ThavinV Jul 12 '23 at 14:27

0 Answers0