Skip to content

* add message body to the error reporter context for SNS/SQS #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/sns/lib/sns/AbstractSnsPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export abstract class AbstractSnsPublisher<MessagePayloadType extends object>
this.handleMessageProcessed(parsedMessage, 'published')
} catch (error) {
const err = error as Error
this.handleError(err)
this.handleError(err, { message: JSON.stringify(message) })
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be conditional in some way. e. g. there could be a protected method on a publisher for serializing the payload

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this relevant for publisher only?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, for all cases, we want to prevent potentially too large or sensitive payloads from being logged

throw new InternalError({
message: `Error while publishing to SNS: ${err.message}`,
errorCode: 'SNS_PUBLISH_ERROR',
Expand Down
10 changes: 5 additions & 5 deletions packages/sqs/lib/sqs/AbstractSqsConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export abstract class AbstractSqsConsumer<
messageType,
)
.catch((err) => {
this.handleError(err)
this.handleError(err, { parsedMessage: JSON.stringify(parsedMessage) })
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
return { error: err }
})
Expand Down Expand Up @@ -358,7 +358,7 @@ export abstract class AbstractSqsConsumer<
private tryToExtractId(message: SQSMessage): Either<'abort', string> {
const resolveMessageResult = this.resolveMessage(message)
if (isMessageError(resolveMessageResult.error)) {
this.handleError(resolveMessageResult.error)
this.handleError(resolveMessageResult.error, { message: message.Body })
return ABORT_EARLY_EITHER
}
// Empty content for whatever reason
Expand All @@ -384,7 +384,7 @@ export abstract class AbstractSqsConsumer<

const resolveMessageResult = this.resolveMessage(message)
if (isMessageError(resolveMessageResult.error)) {
this.handleError(resolveMessageResult.error)
this.handleError(resolveMessageResult.error, { message: message.Body })
return ABORT_EARLY_EITHER
}
// Empty content for whatever reason
Expand All @@ -396,7 +396,7 @@ export abstract class AbstractSqsConsumer<
resolveMessageResult.result as MessagePayloadType,
)
if (resolveSchemaResult.error) {
this.handleError(resolveSchemaResult.error)
this.handleError(resolveSchemaResult.error, { message: message.Body })
return ABORT_EARLY_EITHER
}

Expand All @@ -406,7 +406,7 @@ export abstract class AbstractSqsConsumer<
this.errorResolver,
)
if (isMessageError(deserializationResult.error)) {
this.handleError(deserializationResult.error)
this.handleError(deserializationResult.error, { message: message.Body })
return ABORT_EARLY_EITHER
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sqs/lib/sqs/AbstractSqsPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export abstract class AbstractSqsPublisher<MessagePayloadType extends object>
this.handleMessageProcessed(parsedMessage, 'published')
} catch (error) {
const err = error as Error
this.handleError(err)
this.handleError(err, { message: JSON.stringify(message) })
throw new InternalError({
message: `Error while publishing to SQS: ${err.message}`,
errorCode: 'SQS_PUBLISH_ERROR',
Expand Down
Loading