From 0bf0d5af70fbfbefcac2bc238084574a74b7cf6a Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Fri, 21 Jul 2023 16:52:53 +0200 Subject: [PATCH] fixup! refactor(coap-server): refactor request handling --- packages/binding-coap/src/coap-server.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/binding-coap/src/coap-server.ts b/packages/binding-coap/src/coap-server.ts index 5c3025ef3..c3af34511 100644 --- a/packages/binding-coap/src/coap-server.ts +++ b/packages/binding-coap/src/coap-server.ts @@ -516,10 +516,12 @@ export default class CoapServer implements ProtocolServer { try { await thing.handleObserveProperty(affordanceKey, listener, null); - } finally { - res.end(); + } catch (error) { + warn(error.toString()); } + res.end(); + res.on("finish", (err: Error) => { if (err) { error(`CoapServer on port ${this.port} failed on observe with: ${err.message}`); @@ -677,10 +679,12 @@ export default class CoapServer implements ProtocolServer { try { await thing.handleSubscribeEvent(affordanceKey, listener, interactionOptions); - } finally { - res.end(); + } catch (error) { + warn(error.toString()); } + res.end(); + res.on("finish", () => { debug( `CoapServer on port ${this.getPort()} ends '${affordanceKey}' observation from ${Helpers.toUriLiteral(