Closed ecabaner closed 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); }; }); }
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.
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)) }