diff --git a/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala b/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala index cbf81e8..e6e7d12 100644 --- a/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala +++ b/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala @@ -74,11 +74,12 @@ object CzechPostDeliveryCheck { } def latestStatePrint(parcelId: String): String = { - val state = latestState - s"$parcelId ($comment) - ${printDateFormat.format(czechPostDateFormat.parse(state.date))} - ${state.text}" + latestState + .map(state => s"$parcelId ($comment) - ${printDateFormat.format(czechPostDateFormat.parse(state.date))} - ${state.text}") + .getOrElse(s"$parcelId ($comment) - NO INFO") } - private def latestState: Entities.State = states.toSeq.maxBy(state => czechPostDateFormat.parse(state.date)) + private def latestState: Option[Entities.State] = states.toSeq.maxByOption(state => czechPostDateFormat.parse(state.date)) } case class State(parcelStates: Map[String, Parcel] = Map.empty) {