From 20b586db6eb9f92cce16d87d0dcfa4919f27ffa8 Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Mon, 8 Nov 2021 13:44:02 +0100 Subject: [PATCH] fix(core): log errors if message is undeliverable (#528) The error message being logged just indicated that a message is undeliverable to a certain connection. It swallowed the underlying errors. This adds an `errors` property to the error log so that it is clear what the underlying errors are when a message is undeliverable. Signed-off-by: Timo Glastra Co-authored-by: Berend Sliedrecht <61358536+blu3beri@users.noreply.github.com> --- packages/core/src/agent/MessageSender.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core/src/agent/MessageSender.ts b/packages/core/src/agent/MessageSender.ts index d0bbdb256e..da39dd9fe4 100644 --- a/packages/core/src/agent/MessageSender.ts +++ b/packages/core/src/agent/MessageSender.ts @@ -86,6 +86,8 @@ export class MessageSender { packedMessage: WireMessage options?: { transportPriority?: TransportPriorityOptions } }) { + const errors: Error[] = [] + // Try to send to already open session const session = this.transportService.findSessionByConnectionId(connection.id) if (session?.inboundMessage?.hasReturnRouting()) { @@ -93,7 +95,8 @@ export class MessageSender { await session.send(packedMessage) return } catch (error) { - this.logger.info(`Sending packed message via session failed with error: ${error.message}.`, error) + errors.push(error) + this.logger.debug(`Sending packed message via session failed with error: ${error.message}.`, error) } } @@ -141,6 +144,7 @@ export class MessageSender { // Message is undeliverable this.logger.error(`Message is undeliverable to connection ${connection.id} (${connection.theirLabel})`, { message: packedMessage, + errors, connection, }) throw new AriesFrameworkError(`Message is undeliverable to connection ${connection.id} (${connection.theirLabel})`) @@ -153,6 +157,7 @@ export class MessageSender { } ) { const { connection, payload } = outboundMessage + const errors: Error[] = [] this.logger.debug('Send outbound message', { message: payload, @@ -167,7 +172,8 @@ export class MessageSender { await this.sendMessageToSession(session, payload) return } catch (error) { - this.logger.info(`Sending an outbound message via session failed with error: ${error.message}.`, error) + errors.push(error) + this.logger.debug(`Sending an outbound message via session failed with error: ${error.message}.`, error) } } @@ -189,6 +195,7 @@ export class MessageSender { }) return } catch (error) { + errors.push(error) this.logger.debug( `Sending outbound message to service with id ${service.id} failed with the following error:`, { @@ -218,6 +225,7 @@ export class MessageSender { // Message is undeliverable this.logger.error(`Message is undeliverable to connection ${connection.id} (${connection.theirLabel})`, { message: payload, + errors, connection, }) throw new AriesFrameworkError(`Message is undeliverable to connection ${connection.id} (${connection.theirLabel})`)