Reputation: 6715
I came across this issue already a couple of times and I wonder what the Lift-way is to perform such an action. Of course I could do my own error handling etc. but basically I wonder how I can turn a Box[Elem] into a LiftResponse. Ideally an XmlResponse of course.
The scenario is that I am using the RestHelper for an API and I have a function that returns me a Box[Elem]. I would like to make use of the async support.
The error I get is that Box[Elem] (or Box[NodeSeq], Box[Node]) cannot be converted to LiftResponse. However the exact same code without using RestContinuation works.
Note: I do not want Lift to do any template processing logic. Just output the XML the same way it would happen without using RestContinuation.
val userId = S.param("userId") map { _.toInt }
RestContinuation.async {
reply => {
reply(
for {
user <- userRepo.select(userId) ?~ "No such user." ~> 404
} yield {
<user>
<name>{user.name}</name>
</user>
}
)
}
}
Upvotes: 1
Views: 262
Reputation: 67888
I think there is an implicit
declaration missing. You can bring this implicit (implicit def canNodeToResponse(in: Box[Seq[Node]]): LiftResponse
in scope by mixing-in the trait
XMLApiHelper
in the surrounding class.
Upvotes: 1