tlsd 2.6.5 → 2.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tlsd",
3
- "version": "2.6.5",
3
+ "version": "2.6.7",
4
4
  "description": "A server for web app prototyping with HTTPS and Websockets",
5
5
  "main": "tlsd.js",
6
6
  "bin": {
@@ -98,7 +98,7 @@
98
98
 
99
99
  const waiting = new WaitList()
100
100
 
101
- const send = function(m, cb) {
101
+ const send = function(m, cb, fail) {
102
102
  DBG( "send: " + o2j( m ) );
103
103
  if(m.msg_id === undefined) {
104
104
  m.msg_id = "CMID-" + next_seq(); // every message must have an id
@@ -106,7 +106,7 @@
106
106
 
107
107
  // put msg into waiting list if caller is expecting a reply
108
108
  if(cb) {
109
- waiting.ins( { msg: m, cb: cb }, m.msg_id );
109
+ waiting.ins( { msg: m, cb, fail }, m.msg_id );
110
110
  }
111
111
 
112
112
  DBG(">>---> server "+o2j( m ));
@@ -162,6 +162,24 @@
162
162
  return;
163
163
  }
164
164
 
165
+ if( typeof msg_in.error !== "undefined" ) {
166
+ // error response to a client initiated msg
167
+ var x = waiting.rem( msg_in.msg_id );
168
+ if( ! x ) {
169
+ cb_ctrl( "warning", "invalid reply", msg_in.msg_id );
170
+ return;
171
+ }
172
+
173
+ // route response to associated error call back
174
+ var m = x.msg
175
+ var fail = x.fail;
176
+ if( fail ) {
177
+ fail(msg_in.error);
178
+ }
179
+
180
+ return
181
+ }
182
+
165
183
  if( typeof msg_in.response !== "undefined" ) {
166
184
  // response to a client initiated msg
167
185
 
@@ -209,7 +227,7 @@
209
227
  };
210
228
 
211
229
  const via_ws = function( msg, okay = ()=>{}, fail = ()=>{} ) {
212
- conn.send( { msg }, okay );
230
+ conn.send( { msg }, okay, fail );
213
231
  };
214
232
 
215
233
  const connect = function( cb ) {
package/tlsd.js CHANGED
@@ -57,7 +57,7 @@ const rpc_handler = function( root, msg, xport, _okay, _fail ) {
57
57
  };
58
58
 
59
59
  const ouch = audit_error => {
60
- E( root + ": " + audit_error );
60
+ E( root + ": " + o2j(audit_error) );
61
61
  fail( "RPC error" ); // this is returned to browser
62
62
  };
63
63
 
@@ -82,7 +82,8 @@ const ws_msg_handler = function( root, msg ) {
82
82
  rpc_handler( root, msg.msg, "WS", data => {
83
83
  msg.reply( data );
84
84
  }, error => {
85
- E( "This shouldn't happen: "+o2j(error,null,2) );
85
+ msg.error( { error } );
86
+ E( "Should this happen? "+o2j(error,null,2) );
86
87
  } );
87
88
  };
88
89