Skip to content

Commit ec1d4d3

Browse files
Mohit TejaniMohit Tejani
authored andcommitted
logger changes for printing http protocol details when available with node transport.
1 parent 6d06854 commit ec1d4d3

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

lib/loggers/console-logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ConsoleLogger {
105105
const formattedBody = this.formattedBody(message);
106106
const padding = ((formattedBody === null || formattedBody === void 0 ? void 0 : formattedBody.formData) ? 'Headers' : 'Status').length;
107107
const response = message.message;
108-
return `Received HTTP response:\n ${this.paddedString('URL', padding)}: ${response.url}\n ${this.paddedString('Status', padding)}: ${response.status}${headersList ? `\n ${this.paddedString('Headers', padding)}:\n${headersList}` : ''}${(formattedBody === null || formattedBody === void 0 ? void 0 : formattedBody.body) ? `\n ${this.paddedString('Body', padding)}:\n${formattedBody.body}` : ''}`;
108+
return `Received HTTP response:\n ${this.paddedString('URL', padding)}: ${response.url}\n ${this.paddedString('Status', padding)}: ${response.status}${message.details ? `\n ${this.paddedString('Details', padding)}: ${message.details}` : ''}${headersList ? `\n ${this.paddedString('Headers', padding)}:\n${headersList}` : ''}${(formattedBody === null || formattedBody === void 0 ? void 0 : formattedBody.body) ? `\n ${this.paddedString('Body', padding)}:\n${formattedBody.body}` : ''}`;
109109
}
110110
else if (message.messageType === 'error') {
111111
const formattedStatus = this.formattedErrorStatus(message);

lib/types/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,6 +3342,11 @@ declare namespace PubNub {
33423342
* Object with data received from a transport-specific response object.
33433343
*/
33443344
message: TransportResponse;
3345+
/**
3346+
* Additional information which can be useful alongside the response (e.g. the application-layer
3347+
* protocol negotiated for the connection).
3348+
*/
3349+
details?: string;
33453350
};
33463351

33473352
/**

src/core/interfaces/logger.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ export type NetworkResponseLogMessage = BaseLogMessage & {
202202
* Object with data received from a transport-specific response object.
203203
*/
204204
message: TransportResponse;
205+
206+
/**
207+
* Additional information which can be useful alongside the response (e.g. the application-layer
208+
* protocol negotiated for the connection).
209+
*/
210+
details?: string;
205211
};
206212

207213
/**

src/loggers/console-logger.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ export class ConsoleLogger implements Logger {
145145
return `Received HTTP response:\n ${this.paddedString('URL', padding)}: ${
146146
response.url
147147
}\n ${this.paddedString('Status', padding)}: ${response.status}${
148-
headersList ? `\n ${this.paddedString('Headers', padding)}:\n${headersList}` : ''
149-
}${formattedBody?.body ? `\n ${this.paddedString('Body', padding)}:\n${formattedBody.body}` : ''}`;
148+
message.details ? `\n ${this.paddedString('Details', padding)}: ${message.details}` : ''
149+
}${headersList ? `\n ${this.paddedString('Headers', padding)}:\n${headersList}` : ''}${
150+
formattedBody?.body ? `\n ${this.paddedString('Body', padding)}:\n${formattedBody.body}` : ''
151+
}`;
150152
} else if (message.messageType === 'error') {
151153
const formattedStatus = this.formattedErrorStatus(message);
152154
const error = message.message;

0 commit comments

Comments
 (0)