Skip to content
Snippets Groups Projects
Commit 271dca08 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Throw an Error instance (as an exception) instead of a string.

This enables much easier debugging of logged exceptions/errors.
parent 39a77d9a
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #242 passed
...@@ -69,11 +69,11 @@ function JSONClient(serverAddr,serverPort) { ...@@ -69,11 +69,11 @@ function JSONClient(serverAddr,serverPort) {
this.VERSION = "$Revision: 1.29 $".replace(/\$/g,'').split(' ')[1]; this.VERSION = "$Revision: 1.29 $".replace(/\$/g,'').split(' ')[1];
this.serverAddr=serverAddr; this.serverAddr=serverAddr;
if(this.serverAddr==undefined) if(this.serverAddr==undefined)
throw("no host specified"); throw new Error("no host specified");
this.serverPort=serverPort; this.serverPort=serverPort;
if(this.serverPort==undefined) if(this.serverPort==undefined)
throw("no port specified"); throw new Error("no port specified");
this.settings={ this.settings={
CONNECTION_TIMEOUT: 10, CONNECTION_TIMEOUT: 10,
...@@ -104,7 +104,7 @@ function JSONClient(serverAddr,serverPort) { ...@@ -104,7 +104,7 @@ function JSONClient(serverAddr,serverPort) {
if(!this.socket.connect(this.serverAddr,this.serverPort,this.settings.CONNECTION_TIMEOUT)) { if(!this.socket.connect(this.serverAddr,this.serverPort,this.settings.CONNECTION_TIMEOUT)) {
var connect_error = this.socket.error var connect_error = this.socket.error
this.socket.close(); this.socket.close();
throw("error " + connect_error + " (" + socket_errno_str + ") connecting to TCP port " + this.serverPort + " on server " + this.serverAddr); throw new Error("error " + connect_error + " (" + socket_errno_str + ") connecting to TCP port " + this.serverPort + " on server " + this.serverAddr);
} }
return true; return true;
} }
...@@ -348,7 +348,7 @@ function JSONClient(serverAddr,serverPort) { ...@@ -348,7 +348,7 @@ function JSONClient(serverAddr,serverPort) {
/* package a query and send through the socket */ /* package a query and send through the socket */
this.send=function(packet) { this.send=function(packet) {
if(!this.socket.is_connected) if(!this.socket.is_connected)
throw("socket disconnected 1"); throw new Error("socket disconnected 1");
this.socket.sendJSON(packet); this.socket.sendJSON(packet);
} }
...@@ -368,7 +368,7 @@ function JSONClient(serverAddr,serverPort) { ...@@ -368,7 +368,7 @@ function JSONClient(serverAddr,serverPort) {
this.socket.pingIn(packet); this.socket.pingIn(packet);
return false; return false;
case "ERROR": case "ERROR":
throw(packet.data.description); throw new Error(packet.data.description);
return false; return false;
} }
return packet; return packet;
...@@ -390,7 +390,7 @@ function JSONClient(serverAddr,serverPort) { ...@@ -390,7 +390,7 @@ function JSONClient(serverAddr,serverPort) {
else else
this.updates.push(packet); this.updates.push(packet);
} while(Date.now() - start < this.settings.SOCK_TIMEOUT); } while(Date.now() - start < this.settings.SOCK_TIMEOUT);
throw("timed out waiting for server response"); throw new Error("timed out waiting for server response");
} }
/* check socket for data, and process it if a callback is specified */ /* check socket for data, and process it if a callback is specified */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment