Basically, this function returns a list of flights for an airline. But if the airline doesn't exist, I want to throw some custom runtime exception. If that airline does exist, I want to return a list of flights (which could potentially be empty).
Is this is the standard way of doing things in Scala, or is there a better way to write this code?
Coming from a Java background, I'm still trying to get to grips with the Scala way of doing things.
def getFlightsForAirline(id:Long):Try[Option[List[Flight]]] = {
val maybeAirline:Option[Airline] = Airline.getById(id)
maybeAirline match {
case Some(airline) => {
Success(Flight.getFlightsByAirline(airline))
}
case None => Failure(new RecordNotFoundException("Couldnt find airline"))
}
}