Last active
August 29, 2015 13:58
-
-
Save gbougeard/10017042 to your computer and use it in GitHub Desktop.
Use zip to find errors refs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val futures = for { | |
o <- Future.sequence(list.map(Jira.getIssue)) | |
} yield o | |
futures.map(results => { | |
val jsonIssues: List[Option[Issue]] = results.map(result => { | |
result.json.validate[Issue] match { | |
case s: JsSuccess[Issue] => Some(s.get) | |
case e: JsError => { | |
Logger.debug("Errors: " + JsError.toFlatJson(e).toString()) | |
None | |
} | |
} | |
}) | |
val issues:List[(Option[Issue], String)] = jsonIssues zip list | |
issues.filter(_._1 == None).map(r => Logger.debug(s"ref $r not found")) | |
// ).collect { | |
// case Some(i) => i | |
// } | |
// play.Logger.debug(s"$jsonIssues") | |
val releaseNote = new ReleaseNote(ref, | |
jsonIssues.flatten.filter(_.key.startsWith("RIT")).distinct.groupBy(_.custId), | |
jsonIssues.flatten.filter(_.key.startsWith("BUG")).distinct.groupBy(_.custId), | |
commits) | |
Ok(views.html.releaseNotes(releaseNote)) | |
}) |
ça t'irait ça ?
def logErrors(errors:...)= Logger.debug("Errors: " + JsError.toFlatJson(e).toString())
results.flatMap( result=>
result.json.validate[Issue].fold(
errors => {logErrors(errors); List.empty[Issue]},
issue => List(issue)
)
puisque tu veux juste logger les erreurs
jean
@Ugo je n'ai pas encore l'habitude de jouer avec les Either. Je ne suis qu'un part-time scalafist :'(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
t'as essayé validate[Issue].asEither ?