def apply()

in schedulelambda/src/main/scala/com/gu/notificationschedule/notifications/RequestNotification.scala [28:59]


  def apply(nowEpoch: Long, notificationsScheduleEntry: NotificationsScheduleEntry): Try[Unit] = {
    cloudWatchMetrics.timeTry("notification-request", () =>
      tryRequestNotification(notificationsScheduleEntry) match {
        case Success(Some(response)) => {
          try {
            if (response.isSuccessful) {
              logger.info("Success: request: {}\n Got response {} ", notificationsScheduleEntry: Any, response: Any)
              Success(())
            }
            else {
              logger.warn("Unsuccessful response: request: {}\nGot response {} ", notificationsScheduleEntry: Any, response: Any)
              Failure(new RequestNotificationException(s"Unsuccessful response.\nRequest: $notificationsScheduleEntry\nResponse: $response"))
            }
          }
          finally {
            Option(response.body).foreach(_.close)
          }


        }
        case Success(None) => {
          logger.warn("No response: request: {}", notificationsScheduleEntry)
          Failure(new RequestNotificationException(s"Missing response.\nRequest: $notificationsScheduleEntry\n"))
        }
        case Failure(t) => {
          logger.warn(s"Failed request: $notificationsScheduleEntry", t)
          Failure(t)
        }
      }
    )

  }