Skip to content

Commit

Permalink
fix: on invalid package only emit error if listeners available
Browse files Browse the repository at this point in the history
  • Loading branch information
Krauskopf Sebastian (DC-AE/EAR2) committed Dec 6, 2024
1 parent 4b7368e commit 532abb1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ Any use of the source code and related documents of this repository in applicati
* 2024-03-19: 1.9.5 - fix: update dependencies in package-lock
* 2024-05-24: 1.9.6 - fix: catch exception when server sends invalid/incomplete json in subscription (Bug849302).
- fix: add more tests to handle node address with invalid symbols
* 2024-12-06: 1.9.7 - fix: update dependencies in package-lock
- fix: further improve resilience on invalid data from server
```

## About
Expand Down
8 changes: 6 additions & 2 deletions lib/CtrlxDatalayerSubscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ class CtrlxDatalayerSubscription extends EventEmitter {
setTimeout(()=>this.emit('update', payload, e.lastEventId), 0);
}
} catch (err) {
this.emit('error', new Error(`Error parsing update event: ${err.message}`));
if (this.listeners('error').length > 0) {
this.emit('error', new Error(`Error parsing update event: ${err.message}`));
}
}

});
Expand All @@ -452,7 +454,9 @@ class CtrlxDatalayerSubscription extends EventEmitter {
setTimeout(()=>this.emit('keepalive', payload, e.lastEventId), 0);
}
} catch (err) {
this.emit('error', new Error(`Error parsing keepalive event: ${err.message}`));
if (this.listeners('error').length > 0) {
this.emit('error', new Error(`Error parsing keepalive event: ${err.message}`));
}
}
});

Expand Down

0 comments on commit 532abb1

Please sign in to comment.