Play framework error: type mismatch - found scala.concurrent.Future[play.api.mvc.Result] required: play.api.mvc.Result

Play framework error: type mismatch - found scala.concurrent.Future[play.api.mvc.Result] required: play.api.mvc.Result

我在 play-scala 项目的控制器中有以下代码。

def removeItemFromShoppingBag: Action[JsValue] = Action(parse.json) {
    implicit request =>
      request.body.validate[RemoveItem]
       .fold(
         errors =>
            BadRequest(Json.obj("status" -> "KO", "message" -> JsError.toJson(errors))),
         removeItem => {
           productService.retrieve(removeItem.itemID).flatMap {
             case Some(item) => productInTheBagService.retrieve(item.id).flatMap {
               case Some(itemInTheBag) =>
                 Future.successful(
                   Ok(ApiResponse("shopping.products", Messages("request.ok")))
                 )
               case None =>
                 Future.successful(
                   BadRequest(ApiResponse("home.shopping.item.not.available",
                      Messages("shopping.item.not.available")))
          )
        }

        case None =>
          Future.successful(
            BadRequest(ApiResponse("home.shopping.item.not.available",
              Messages("shopping.item.not.available")))
          )
        }
      }
    )
   }

编译时出现如下错误:

Controller.scala:236:62: type mismatch;
[error]  found   : scala.concurrent.Future[play.api.mvc.Result]
[error]  required: play.api.mvc.Result
[error]           productService.retrieve(removeItem.itemID).flatMap {
[error]                                                              ^
[error] one error found

我读过类似问题的答案: 但这没有帮助。

如有任何帮助,我将不胜感激。

你需要Action.async(parse.json)到return一个Future