Skip to content

Commit

Permalink
fix(core): log errors if message is undeliverable (#528)
Browse files Browse the repository at this point in the history
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 <timo@animo.id>
Co-authored-by: Berend Sliedrecht <61358536+blu3beri@users.noreply.github.com>
  • Loading branch information
TimoGlastra and berendsliedrecht committed Nov 8, 2021
1 parent 3db5519 commit 20b586d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/core/src/agent/MessageSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,17 @@ 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()) {
try {
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)
}
}

Expand Down Expand Up @@ -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})`)
Expand All @@ -153,6 +157,7 @@ export class MessageSender {
}
) {
const { connection, payload } = outboundMessage
const errors: Error[] = []

this.logger.debug('Send outbound message', {
message: payload,
Expand All @@ -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)
}
}

Expand All @@ -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:`,
{
Expand Down Expand Up @@ -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})`)
Expand Down

0 comments on commit 20b586d

Please sign in to comment.