Reputation: 21
At getOrElse
in the code that follows, I'm getting the following error:
type mismatch; found : Object required: play.api.mvc.Result
What is wrong? I'm usinging playframework2.2
def onUnauthorized(request: RequestHeader) =
Results.BadRequest(Json.obj("error" -> "Invalid signature"))
def withUserSigner(f: User => Request[Map[String, Seq[String]]] => Result) = Action(BodyParsers.parse.urlFormEncoded) {
request =>
val userOpt = request.body.get(SRT_ACCESS_KEY).flatMap { email =>
DB.withConnection { implicit connection =>
User.findByEmail(email.mkString).flatMap { user =>
getSigner(request.method, request.path, request.body, user)
}
}
}
userOpt.map { user =>
Action(BodyParsers.parse.urlFormEncoded) { request => f(user)(request) }(request)
}.getOrElse { *//got error in this line "type mismatch; found : Object required: play.api.mvc.Result"*
onUnauthorized(request)
}
}
Upvotes: 1
Views: 2927
Reputation: 7247
The problem is in this snippet:
userOpt.map { user =>
Action(BodyParsers.parse.urlFormEncoded) { request => f(user)(request) }(request)
}.getOrElse {
onUnauthorized(request)
}
In your map
you're calling Action
which just returns an Action
, not a Result
. The type returned by getOrElse
is an object because it's the common ancestor of both Result
and Action
.
Since you have both the user and request required to invoke f
, you should just do this:
userOpt.map { user =>
f(user)(request)
}.getOrElse {
onUnauthorized(request)
}
Upvotes: 1