diff --git a/packages/binding-mqtt/src/mqtt-client.ts b/packages/binding-mqtt/src/mqtt-client.ts index 9fc120155..b68a79220 100644 --- a/packages/binding-mqtt/src/mqtt-client.ts +++ b/packages/binding-mqtt/src/mqtt-client.ts @@ -65,7 +65,10 @@ export default class MqttClient implements ProtocolClient { const brokerUri: string = `${this.scheme}://` + requestUri.host; // Keeping the path as the topic for compatibility reasons. // Current specification allows only form["mqv:filter"] - const filter = requestUri.pathname.slice(1) ?? form["mqv:filter"]; + const filter = requestUri.pathname.slice(1) || form["mqv:filter"]; + if (filter == null) { + throw new Error("MqttClient: no filter found in form href or mqv:filter"); + } let pool = this.pools.get(brokerUri); @@ -95,7 +98,10 @@ export default class MqttClient implements ProtocolClient { const brokerUri: string = `${this.scheme}://` + requestUri.host; // Keeping the path as the topic for compatibility reasons. // Current specification allows only form["mqv:filter"] - const filter = requestUri.pathname.slice(1) ?? form["mqv:filter"]; + const filter = requestUri.pathname.slice(1) || form["mqv:filter"]; + if (filter == null) { + throw new Error("MqttClient: no filter found in form href or mqv:filter"); + } let pool = this.pools.get(brokerUri); @@ -125,7 +131,10 @@ export default class MqttClient implements ProtocolClient { public async writeResource(form: MqttForm, content: Content): Promise { const requestUri = new url.URL(form.href); const brokerUri = `${this.scheme}://${requestUri.host}`; - const topic = requestUri.pathname.slice(1) ?? form["mqv:topic"]; + const topic = requestUri.pathname.slice(1) || form["mqv:topic"]; + if (topic == null) { + throw new Error("MqttClient: no topic found in form href or mqv:topic"); + } let pool = this.pools.get(brokerUri);