From 38e7da5d7e9697f5b1e52b954b168700a38abb93 Mon Sep 17 00:00:00 2001
From: Manos Angelidis <angelidis@fortiss.org>
Date: Wed, 11 Nov 2020 16:45:08 +0000
Subject: [PATCH] [NRRPLT-7962] Added error propagation mechanism from opensim
 to frontend

Merged in NRRPLT-7962 (pull request #41)

- New subscriber for the ~/error topic
- Functionality that checks whether the error is coming from opensim
  mesh handling and propagates the error to the frontend

Approved-by: Stefano Nardo
Approved-by: Sandro Weber
---
 gz3d/src/gziface.js     | 19 +++++++++++++++++++
 gz3d/src/gzsdfparser.js |  5 +++++
 2 files changed, 24 insertions(+)

diff --git a/gz3d/src/gziface.js b/gz3d/src/gziface.js
index b428761..9c691a2 100644
--- a/gz3d/src/gziface.js
+++ b/gz3d/src/gziface.js
@@ -158,6 +158,25 @@ GZ3D.GZIface.prototype.onConnected = function() {
   };
   this.statusTopic.subscribe(statusUpdate.bind(this));
 
+  this.errorTopic = new ROSLIB.Topic({
+    ros: this.webSocket,
+    name: '~/error',
+    messageType: 'error'
+  });
+
+  var errorUpdate = function (message) {
+    // error with id 1 means that opensim faied to load a mesh
+    if (message.id === 1) {
+      this.emitter.emit('opensimMeshError', message);
+    }
+    // generic gazebo error handling
+    else {
+      console.error(`Error received from gazebo: ${message}`);
+    }
+  };
+
+  this.errorTopic.subscribe(errorUpdate.bind(this));
+
   this.materialTopic = new ROSLIB.Topic({
     ros: this.webSocket,
     name: '~/material',
diff --git a/gz3d/src/gzsdfparser.js b/gz3d/src/gzsdfparser.js
index c501800..b42782a 100644
--- a/gz3d/src/gzsdfparser.js
+++ b/gz3d/src/gzsdfparser.js
@@ -51,6 +51,11 @@ GZ3D.SdfParser.prototype.init = function() {
       that.onConnectionError();
     }
   });
+
+  this.gziface.emitter.on('opensimMeshError', function (error) {
+    that.gui.guiEvents.emit('opensimMeshError', error, 5000);
+    that.onConnectionError();
+  });
 };
 
 /**
-- 
GitLab