PantelisGeorgiadis / dcmjs-dimse

DICOM DIMSE implementation for Node.js using the dcmjs library
MIT License
73 stars 14 forks source link

Unhandled error when connection data is invalid #1

Closed ecabaner closed 3 years ago

ecabaner commented 3 years ago

When trying to make a connection with an incorrect IP or PORT, it gives an error in the console. This error cannot be handled with a catch.

this.socket.on("error", err=>{ this._reset(); const error = ${this.logId} -> Connection error: ${err.message}; log.error(error); this.emit("networkError", new Error(error)) }

ecabaner commented 3 years ago

To handle error, use promise and window.onerror event to get console error, example:

function ECHO() { return new Promise((resolve, reject) => { const client = new Client(); const request = new CEchoRequest(); request.on('response', response => { if (response.getStatus() === Status.Success) { resolve(); } else { reject(); } }).on('networkError', e => { reject(e); }); client.addRequest(request); client.send(ip, port, AET_SERVER, AET_ORIGIN); window.onerror = function(error, url, line) { reject(error); }; }); }

PantelisGeorgiadis commented 3 years ago

Thank you @ecabaner! All network-related errors are now being forwarded to the “networkError” client handler, including the case when the connection data is invalid. Please check the updated README for sample code.