Skip to content

Commit

Permalink
refactor: Improve logging and error handling in Connection class
Browse files Browse the repository at this point in the history
  • Loading branch information
drazisil committed May 8, 2024
1 parent d08682f commit 26bcf21
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/connection/src/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function createDataEncryptionPair(key: string): McosEncryptionPair {
log.error(`Key is empty: ${key}`);
throw new ErrorNoKey(`Key is empty: ${key}`);
}

Check warning on line 74 in packages/connection/src/Connection.ts

View check run for this annotation

Codecov / codecov/patch

packages/connection/src/Connection.ts#L71-L74

Added lines #L71 - L74 were not covered by tests

if (key.length < 16) {
log.error(`Key too short: length ${key.length}, value ${key}`);
throw Error(`Key too short: length ${key.length}, value ${key}`);
Expand Down Expand Up @@ -265,15 +265,19 @@ export class Connection {
);
try {
messages.forEach((message) => {

Check warning on line 267 in packages/connection/src/Connection.ts

View check run for this annotation

Codecov / codecov/patch

packages/connection/src/Connection.ts#L262-L267

Added lines #L262 - L267 were not covered by tests
this._logger.debug(`Sending server message header: ${message.header.toString()}`);
this._logger.debug(
`Sending server message header: ${message.header.toString()}`,
);
this._logger.debug(`Server Message: ${message.toHexString()}`);

Check warning on line 271 in packages/connection/src/Connection.ts

View check run for this annotation

Codecov / codecov/patch

packages/connection/src/Connection.ts#L271

Added line #L271 was not covered by tests

message = this.encryptIfNecessary(message);

Check warning on line 273 in packages/connection/src/Connection.ts

View check run for this annotation

Codecov / codecov/patch

packages/connection/src/Connection.ts#L273

Added line #L273 was not covered by tests

if (message.isEncrypted()) {
this._logger.debug(`Encrypted Message: ${message.toHexString()}`);
this._logger.debug(
`Encrypted Message: ${message.toHexString()}`,
);
}

this._socket.write(message.serialize());
if (message.getId() === 0x101) {
this.setChannelSecure(true);
Expand Down Expand Up @@ -350,12 +354,13 @@ export class Connection {
this._logger.debug(
`Decrypted message: message ID ${message.getId()}, prior messsage ID ${message.getPreDecryptedMessageId()}`,
);

Check warning on line 356 in packages/connection/src/Connection.ts

View check run for this annotation

Codecov / codecov/patch

packages/connection/src/Connection.ts#L354-L356

Added lines #L354 - L356 were not covered by tests
this._logger.debug(`Decrypted message: ${message.toHexString()}`);
}
this._logger.resetName();
return message;
}

Check warning on line 362 in packages/connection/src/Connection.ts

View check run for this annotation

Codecov / codecov/patch

packages/connection/src/Connection.ts#L358-L362

Added lines #L358 - L362 were not covered by tests
toString(): string {
toString(): string {
return `Connection ${this._connectionId}, persona ID ${this._personaId}, channel secure ${this._channelSecure}`;
}
}

Check warning on line 366 in packages/connection/src/Connection.ts

View check run for this annotation

Codecov / codecov/patch

packages/connection/src/Connection.ts#L364-L366

Added lines #L364 - L366 were not covered by tests

0 comments on commit 26bcf21

Please sign in to comment.