2016-06-17 84 views
1

嘗試使用簡單控制器播放框架2.5時遇到的錯誤消息令人困惑。下面是我在做什麼:上面寫着使用簡單控制器播放框架2.5錯誤

object UserController extends Controller { 

    def login = Action.async(BodyParsers.parse.json) { request => 
    val body = request.body.validate[UserLogin] 
    // call the userService and validate the credentials 
    body.fold(
     errors => { 
     BadRequest(Json.obj("status" -> "error", "message" -> JsError.toFlatJson(errors))) 
     }, // error here 
     message => { 
     Ok("") 
     } // error here 
    ) 
    } 
} 

我收到錯誤消息:

"Expression of type Result does not conform to expected type _X" 
+0

我想你可以刪除「異步」呼叫或在「Future.successful」包裹TWE響應 – rethab

回答

1

我需要包裝該呼叫並在未來!所以這裏是如何做到這一點!

object UserController extends Controller { 

    def login = Action.async(BodyParsers.parse.json) { request => 
    val body = request.body.validate[UserLogin] 
    // call the userService and validate the credentials 
    body.fold(
     errors => { 
     Future.successful { BadRequest(Json.obj("status" -> "error", "message" -> JsError.toFlatJson(errors))) } 
     }, // error here 
     message => { 
     Future.successful { Ok("") } 
     } // error here 
    ) 
    } 
} 
+0

可以公開如何? –