Skip to content

Commit fd6b9b3

Browse files
committed
Ensure errors are known by emitting to "error" channel
1 parent a5f27c7 commit fd6b9b3

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/core/Transport.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,25 @@ export abstract class AbstractTransport
7575
/**
7676
* Decodes a raw message received from the transport
7777
* and emits it as a RosbridgeMessage over the "message" event.
78+
* If an error occurs, it is emitted as an "error" event.
7879
*
7980
* The default implementation handles multiple compression formats
8081
* and fragment messages. Subclasses may override this method to provide
8182
* custom handling of raw messages and when to emit messages.
8283
*/
8384
protected handleRawMessage(data: unknown): void {
84-
if (isRosbridgeMessage(data)) {
85-
this.handleRosbridgeMessage(data);
86-
} else if (typeof Blob !== "undefined" && data instanceof Blob) {
87-
this.handleBsonMessage(data);
88-
} else if (data instanceof ArrayBuffer) {
89-
this.handleCborMessage(data);
90-
} else {
91-
this.handleJsonMessage(String(data));
85+
try {
86+
if (isRosbridgeMessage(data)) {
87+
this.handleRosbridgeMessage(data);
88+
} else if (typeof Blob !== "undefined" && data instanceof Blob) {
89+
this.handleBsonMessage(data);
90+
} else if (data instanceof ArrayBuffer) {
91+
this.handleCborMessage(data);
92+
} else {
93+
this.handleJsonMessage(String(data));
94+
}
95+
} catch (error) {
96+
this.emit("error", error);
9297
}
9398
}
9499

@@ -191,7 +196,7 @@ export abstract class AbstractTransport
191196
if (isRosbridgeMessage(data)) {
192197
this.handleRosbridgeMessage(data);
193198
} else {
194-
throw new Error("Decoded BSON data was invalid!");
199+
this.emit("error", new Error("Decoded BSON data was invalid!"));
195200
}
196201
}
197202
};

0 commit comments

Comments
 (0)