Skip to content

Commit 9e196e3

Browse files
Merge pull request #340 from purecloudlabs/STREAM-1271-502-global-exception
[STREAM-1271] - catch debouncedResubscribe error
2 parents c3f06e0 + 50d8964 commit 9e196e3

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313
* [STREAM-1208](https://inindca.atlassian.net/browse/STREAM-1208) - Update axios to 1.13.5 to address vulnerability.
1414

15+
### Fixed
16+
* [STREAM-1271](https://inindca.atlassian.net/browse/STREAM-1271) - Fix unhandled errors during hard reconnect resubscribe in `handleStanzaInstanceChange`
17+
1518
# [v19.5.0](https://github.com/purecloudlabs/genesys-cloud-streaming-client/compare/v19.4.1...v19.5.0)
1619
### Added
1720
* [STREAM-995](https://inindca.atlassian.net/browse/STREAM-995) - Include `missingPermissions` on topic subscribe Error.

src/notifications.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export class Notifications implements StreamingClientExtension {
6363

6464
if (needsToResub) {
6565
this.client.logger.info('resubscribing due to hard reconnect');
66-
void this.debouncedResubscribe();
66+
this.debouncedResubscribe().catch((err) => {
67+
const msg = 'Error resubscribing to topics';
68+
this.client.logger.error(msg, err);
69+
this.client.emit('pubsub:error' as any, { msg, err });
70+
});
6771
}
6872
}
6973

test/unit/notifications.test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('Notifications', () => {
8484
});
8585
notification = new Notifications(client);
8686
stanzaInstance = notification.stanzaInstance = getFakeStanzaClient();
87-
resubSpy = notification.debouncedResubscribe = jest.fn();
87+
resubSpy = notification.debouncedResubscribe = jest.fn().mockResolvedValue({});
8888
});
8989

9090
it('should not resub if same channelId', () => {
@@ -108,6 +108,25 @@ describe('Notifications', () => {
108108
notification.handleStanzaInstanceChange(newInstance);
109109
expect(resubSpy).not.toHaveBeenCalled();
110110
});
111+
112+
it('should emit pubsub:error if hard reconnect resubscribe fails', async () => {
113+
const newInstance = getFakeStanzaClient();
114+
newInstance.channelId = 'newChannel';
115+
const error = new Error('intentional test error');
116+
resubSpy.mockRejectedValue(error);
117+
118+
const errorEvent = new Promise<void>((resolve) => {
119+
(client as unknown as EventEmitter).on('pubsub:error', (err) => {
120+
expect(err.msg).toBe('Error resubscribing to topics');
121+
expect(err.err).toBe(error);
122+
resolve();
123+
});
124+
});
125+
126+
notification.handleStanzaInstanceChange(newInstance);
127+
await errorEvent;
128+
expect(resubSpy).toHaveBeenCalledTimes(1);
129+
});
111130
});
112131

113132
describe('enablePartialBulkResubscribe', () => {

0 commit comments

Comments
 (0)