Metric Imperial Converter: Res is undefined on invalid input

Anyone has a good explanation to the issues I experienced below?
I wrote:

            assert.equal(res.status, 200);
            assert.equal(res.type, "application/json");

for successful queries and they work fine. But

            // assert.equal(res.type, "text/html");
            // assert.equal(res.text, 'invalid number and unit');
            assert.equal(res, undefined)
            done();

the same two lines test for invalid input (the commented out ones) won’t pass npm test. I passed all the specs just by having that assert.equal(res, undefined)

So it seems on invalid inputs, the res is simply not there. I could not create one nor modify. A console.log(err) on that particular
test yielded:

Error: connect ECONNREFUSED 127.0.0.1:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 80,
  response: undefined
}

A little google and it seems the problem is caused by different port where the request addressed and the proxy setting is (https://community.postman.com/t/error-connect-econnrefused-127-0-0-1-80/12940), but not sure if actually this is relevant to the res === undefined problem, because the same issue happened when I tried to make the app on local with vscode and github (thus I tried using replit to see if such problem persists)

So, if anyone might have a good explanation of why res is undefined on invalid inputs yet seems to work fine on valid input?

Thanks!

Your project link(s)

solution: https://replit.com/@shugyoza/boilerplate-project-metricimpconverter

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36

Challenge: Metric-Imperial Converter

Link to the challenge: