in app/updates/BreakingNewsUpdate.scala [200:255]
private def sendAlert(
trail: ClientHydratedTrail,
email: String,
collectionId: String
): Future[Option[String]] = {
def handleSuccessfulFuture(result: Either[ApiClientError, UUID]) =
result match {
case Left(error) =>
structuredLogger.putLog(
LogUpdate(HandlingBreakingNewsCollection(collectionId), email),
"error",
Some(new Exception(error.description))
)
Some(error.description)
case Right(_) => None
}
def withExceptionHandling(
block: => Future[Option[String]]
): Future[Option[String]] = {
Try(block) match {
case Success(futureMaybeError) => futureMaybeError
case Failure(t: Throwable) =>
val message =
s"Exception in breaking news client send for trail ${trail.headline} because ${t.getMessage}"
logger.error(message, t)
Future.successful(Some(message))
}
}
if (trail.alert.getOrElse(false)) {
withExceptionHandling({
structuredLogger.putLog(
LogUpdate(
HandlingBreakingNewsTrail(collectionId, trail: ClientHydratedTrail),
email
)
)
val payload = BreakingNewsUpdate.createPayload(trail, email)
client
.send(payload)
.map(handleSuccessfulFuture)
.recover { case NonFatal(e) =>
Some(e.getMessage)
}
})
} else {
logger.error(
s"Failed to send a breaking news alert for trail ${trail} because alert was missing"
)
Future.successful(
Some(
"There may have been a problem in sending a breaking news alert. Please contact central production for information"
)
)
}
}