Question

I have a construct like the following

    handleWith {
               mr: MyRequest =>
                (myactor ? mr).mapTo[Either[BadRequest, GoodResponse]]

             }

Based on the result of the Either, I would like to complete with either a 200 based on the Right response and some sort of 4XX based on the left. I'm not quite sure how to pull the future into a Match, in order to do this though.

Was it helpful?

Solution

If I am interpreting your question correctly, you want to know how to pattern match the Either value? If so, you can do something like:

handleWith {
  mr: MyRequest =>
   (myactor ? mr).mapTo[Either[BadRequest, GoodResponse]] match {
     case Left(badRequest) => someSortOf4xxx(badRequest)
     case Right(goodResponse) => anOkResponse(goodResponse)
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top