Websocketd error handling improved
authorBill Erickson <berickxx@gmail.com>
Tue, 12 Jun 2018 15:16:59 +0000 (11:16 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 12 Jun 2018 15:16:59 +0000 (11:16 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
src/websocket-stdio/osrf-websocket-stdio.c

index 662285a..83e3264 100644 (file)
@@ -508,18 +508,6 @@ static void read_from_osrf() {
     // each message, because any subsequent messages will get stuck in
     // the opensrf receive queue. Process all available messages.
     while ( (tmsg = client_recv(osrf_handle, 0)) ) {
-
-        if (tmsg->is_error) {
-            // tmsg here is likely a bounced message, possibly the result
-            // of a XMPP cancel code 503 (forbidden) from an attempt to
-            // send a message to a service that's not available on the
-            // public XMPP domain.  Treat as irrecoverable.
-            osrfLogError(OSRF_LOG_MARK,
-                "WS XMPP error [%d] occured, exiting", tmsg->error_code);
-            shut_it_down(1);
-            return;
-        }
-
         read_one_osrf_message(tmsg);
         message_free(tmsg);
     }
@@ -599,6 +587,16 @@ static void read_one_osrf_message(transport_message* tmsg) {
     jsonObjectSetKey(msg_wrapper, "log_xid", jsonNewObject(tmsg->osrf_xid));
     jsonObjectSetKey(msg_wrapper, "osrf_msg", jsonParseRaw(tmsg->body));
 
+    if (tmsg->is_error) {
+        // tmsg->sender is the original recipient. they get swapped
+        // in error replies.
+        osrfLogError(OSRF_LOG_MARK,
+            "WS received XMPP error message in response to thread=%s and "
+            "recipient=%s.  Likely the recipient is not accessible/available.",
+            tmsg->thread, tmsg->sender);
+        jsonObjectSetKey(msg_wrapper, "transport_error", jsonNewBoolObject(1));
+    }
+
     msg_string = jsonObjectToJSONRaw(msg_wrapper);
 
     // Send the JSON to STDOUT