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 3b8604c commit 0bf0d5a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/binding-coap/src/coap-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 0bf0d5a

Please sign in to comment.