diff --git a/packages/binding-coap/src/coap-server.ts b/packages/binding-coap/src/coap-server.ts index fab84c86c..5c3025ef3 100644 --- a/packages/binding-coap/src/coap-server.ts +++ b/packages/binding-coap/src/coap-server.ts @@ -514,10 +514,11 @@ export default class CoapServer implements ProtocolServer { } }; - thing - .handleObserveProperty(affordanceKey, listener, null) - .then(() => res.end()) - .catch(() => res.end()); + try { + await thing.handleObserveProperty(affordanceKey, listener, null); + } finally { + res.end(); + } res.on("finish", (err: Error) => { if (err) { @@ -674,10 +675,12 @@ export default class CoapServer implements ProtocolServer { } }; - thing - .handleSubscribeEvent(affordanceKey, listener, interactionOptions) - .then(() => res.end()) - .catch(() => res.end()); + try { + await thing.handleSubscribeEvent(affordanceKey, listener, interactionOptions); + } finally { + res.end(); + } + res.on("finish", () => { debug( `CoapServer on port ${this.getPort()} ends '${affordanceKey}' observation from ${Helpers.toUriLiteral(