in handlers/product-move-api/src/main/scala/com/gu/productmove/SQS.scala [53:100]
override def sendEmail(message: EmailMessage): Task[Unit] =
for {
_ <- ZIO
.attemptBlocking {
sqsClient.sendMessage(
SendMessageRequest.builder
.queueUrl(emailQueueUrl)
.messageBody(message.toJson)
.build(),
)
}
.mapError { ex =>
message.To.ContactAttributes.SubscriberAttributes match {
case attributes: RCtoSPEmailPayloadProductSwitchAttributes =>
new Throwable(
s"Failed to send product switch email message to SQS for sfContactId: ${message.SfContactId} with subscription Number: ${attributes.subscription_id} with error: ${ex.toString} to SQS queue $emailQueueUrl",
ex,
)
case attributes: toRCEmailPayloadProductSwitchAttributes =>
new Throwable(
s"Failed to send product switch email message to SQS for sfContactId: ${message.SfContactId} with subscription Number: ${attributes.subscription_id} with error: ${ex.toString} to SQS queue $emailQueueUrl",
ex,
)
case _: EmailPayloadCancellationAttributes =>
new Throwable(
s"Failed to send subscription cancellation email message to SQS for sfContactId: ${message.SfContactId} with error: ${ex.toString} to SQS queue $emailQueueUrl",
ex,
)
case _: EmailPayloadUpdateAmountAttributes =>
new Throwable(
s"Failed to send update amount email message to SQS for sfContactId: ${message.SfContactId} with error: ${ex.toString} to SQS queue $emailQueueUrl",
ex,
)
}
}
_ <- ZIO.log(
message.To.ContactAttributes.SubscriberAttributes match {
case attributes: RCtoSPEmailPayloadProductSwitchAttributes =>
s"Successfully sent product switch email for sfContactId: ${message.SfContactId} with subscription Number: ${attributes.subscription_id} to SQS queue $emailQueueUrl"
case attributes: toRCEmailPayloadProductSwitchAttributes =>
s"Successfully sent product switch email for sfContactId: ${message.SfContactId} with subscription Number: ${attributes.subscription_id} to SQS queue $emailQueueUrl"
case _: EmailPayloadCancellationAttributes =>
s"Successfully sent subscription cancellation email for sfContactId: ${message.SfContactId} to SQS queue $emailQueueUrl"
case _: EmailPayloadUpdateAmountAttributes =>
s"Successfully sent update amount email for sfContactId: ${message.SfContactId} to SQS queue $emailQueueUrl"
},
)
} yield ()