LP#1776510 JS libs handle transport errors
authorBill Erickson <berickxx@gmail.com>
Tue, 12 Jun 2018 16:12:45 +0000 (12:12 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 5 Nov 2018 15:39:45 +0000 (10:39 -0500)
Teach the websocket client code to look for the transport_error flag
applied to the websocket wrapper message by the websocket gateway when a
request for an unavilable service is made.

When encountered, fire the transport or generic error handler callbacks,
if available.  Avoid any attempts to further process the message.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
src/javascript/opensrf.js

index 394cddd..e18efa5 100644 (file)
@@ -361,6 +361,29 @@ OpenSRF.Session.prototype.setup_single_ws = function() {
                 "Error parsing JSON in shared WS response: " + msg);
             throw E;
         }
+
+        if (msg.transport_error) {
+            // Websockets gateway returns bounced messages (e.g. for
+            // requets to unavailable services) with a transport_error
+            // flag set.  
+            console.error(
+                'Websocket request failed with a transport error', msg);
+
+            var ses = OpenSRF.Session.find_session(msg.thread); 
+            if (ses) {
+                if (msg.osrf_msg && msg.osrf_msg[0]) {
+                    var req = ses.find_request(msg.osrf_msg[0].threadTrace());
+                    if (req) {
+                        var handler = req.ontransporterror || req.onerror;
+                        if (handler) {
+                            handler('Service ' + ses.service + ' unavailable');
+                        }
+                    }
+                }
+            }
+            return; // No viable error handlers
+        }
+
         OpenSRF.Stack.push(                                                        
             new OpenSRF.NetMessage(                                                
                null, null, msg.thread, null, msg.osrf_msg)