cv4pve-api-javascript
cv4pve-api-javascript copied to clipboard
There is no explicit handling for errors that might occur on the request (req) object itself
What happened?
Error reported as follows
node:events:489
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 10.10.10.54:8006
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1570:16)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (node:_http_client:495:9)
at TLSSocket.emit (node:events:511:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '10.10.10.54',
port: 8006
}
In the code below does not handle the req error
https://github.com/Corsinvest/cv4pve-api-javascript/blob/c58f4cb74a56f91cdec52ddb2ee726889ab44a10/src/index.js#L295-L340
We can add an error event listener on the req object to handle potential request errors.
req.on('error', (error) => {
this.#error(error);
reject(error);
});
This way we can use catch to handle errors in our own code
Expected behavior
Please evaluate it.
Relevant log output
No response
Proxmox VE Version
latest
Version (bug)
latest
Version (working)
No response
On what operating system are you experiencing the issue?
Windows, Mac OSX, Linux, Other
Pull Request
- [ ] I would like to do a Pull Request