0

I'm getting an error on my Windows machine but not my mac on the same network. Any idea?

(node:16940) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined
    at E:\xxx.js:28:47
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:16940) 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: 
2)
(node:16940) [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.
function checkNumSatoshis(JWTToken, qrcode) {
  return new Promise((resolve, reject) => {
    axios.get(
        `http://xxx.local/api/v1/xx/xx/invoice?paymentRequest=${qrcode}`,
        {
          headers: {
            Authorization: `JWT ${JWTToken}`,
          },

        }
      )
      .then((res) => resolve(res.data.xx))
      .catch((error) => reject(error.response.data))
  });
}
mrWiga
  • 131
  • 1
  • 2
  • 13
  • 2
    [What is the explicit promise construction antipattern and how do I avoid it?](https://stackoverflow.com/questions/23803743/) – Andreas Jul 09 '21 at 12:07
  • The problem is with the `res`, you are not getting it from the request. A simple fix can be `res?.data` – Apoorva Chikara Jul 09 '21 at 12:09
  • I think windows just doesnt like .local domain? Not getting any data from the request – mrWiga Jul 09 '21 at 12:11

2 Answers2

0

There is an error in setting up the request, so the promise goes to the catch block. However, error.response is undefined because there is no request being made.

Do the following instead to get more information about this error:

 .catch((error) => { console.log(error)})
blurfus
  • 13,485
  • 8
  • 55
  • 61
Mahmoud Awad
  • 103
  • 1
  • 5
  • Thanks. Windows just doesn't like .local domain: Error: connect ECONNREFUSED 127.0.0.1:80. Do you know how to bypass? xxx.local domain is NOT 127.0.0.1. – mrWiga Jul 09 '21 at 12:17
  • I've added xxx.local 192.168.1.xx to C:\WINDOWS\System32\drivers\etc\hosts but it didn't work. I can browse to it but not via nodejs – mrWiga Jul 09 '21 at 12:23
  • Try using postman and request the data from the API and see if there is an error. – Apoorva Chikara Jul 09 '21 at 12:29
  • all ok via Postman. I think axios may not like xxx.local domain which is not local. It can't resolve it. – mrWiga Jul 09 '21 at 12:31
  • Example, the API server is not on 127.0.0.1 but it's resolving to it on Windows machine. Error: connect ECONNREFUSED 127.0.0.1:80 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1148:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 80, config: { url: 'xxx.local/api/v1/lnd/xx/invoice?paymentRequest=xxx', method: 'get', – mrWiga Jul 09 '21 at 12:33
0

Add 192.168.1.x xx.local to your C:\WINDOWS\System32\drivers\etc\hosts fixed. I entered the correct format in the host file

mrWiga
  • 131
  • 1
  • 2
  • 13