MCPcopy
hub / github.com/nestjs/nest / handleStatusUpdates

Method handleStatusUpdates

packages/microservices/client/client-nats.ts:77–148  ·  view source on GitHub ↗
(client: Client)

Source from the content-addressed store, hash-verified

75 }
76
77 public async handleStatusUpdates(client: Client) {
78 for await (const status of client.status()) {
79 const data =
80 status.data && isObject(status.data)
81 ? JSON.stringify(status.data)
82 : status.data;
83
84 switch (status.type) {
85 case 'error':
86 this.logger.error(
87 `NatsError: type: "${status.type}", data: "${data}".`,
88 );
89 break;
90
91 case 'disconnect':
92 this.connectionPromise = Promise.reject(
93 'Error: Connection lost. Trying to reconnect...',
94 );
95 // Prevent unhandled promise rejection
96 this.connectionPromise.catch(() => {});
97
98 this.logger.error(
99 `NatsError: type: "${status.type}", data: "${data}".`,
100 );
101
102 this._status$.next(NatsStatus.DISCONNECTED);
103 this.statusEventEmitter.emit(
104 NatsEventsMap.DISCONNECT,
105 status.data as string,
106 );
107 break;
108
109 case 'reconnecting':
110 this._status$.next(NatsStatus.RECONNECTING);
111 break;
112
113 case 'reconnect':
114 this.connectionPromise = Promise.resolve(client);
115 this.logger.log(
116 `NatsStatus: type: "${status.type}", data: "${data}".`,
117 );
118
119 this._status$.next(NatsStatus.CONNECTED);
120 this.statusEventEmitter.emit(
121 NatsEventsMap.RECONNECT,
122 status.data as string,
123 );
124 break;
125
126 case 'pingTimer':
127 if (this.options.debug) {
128 this.logger.debug(
129 `NatsStatus: type: "${status.type}", data: "${data}".`,
130 );
131 }
132 break;
133
134 case 'update':

Callers 3

connectMethod · 0.95

Calls 8

isObjectFunction · 0.90
statusMethod · 0.65
errorMethod · 0.65
catchMethod · 0.65
resolveMethod · 0.65
logMethod · 0.65
debugMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected