Skip to content

Commit

Permalink
fixup! refactor(coap-server): refactor request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jul 21, 2023
1 parent d126936 commit 3b8604c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/binding-coap/src/coap-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 3b8604c

Please sign in to comment.