I am using Play 2.8 and trying to return error messages in Json format.
I tried
Results.InternalServerError(
Json.obj(“status”->“failed”, “reason”->“Timedout”))
as well as
Results.InternalServerError(
Json.obj(“status”->“failed”, “reason”->“Timedout”).toString)
but the response is coming back as a string instead of json.
I have a simpla call which is very similar to what you described
def sample() =
Action.async { implicit request: Request[AnyContent] =>
…
Results.InternalServerError(
Json.obj(“status”->“failed”, “reason”->“Timedout”))
)
}
On the client end the response is "“status”:“failed”,“reason”:There is already an account ““status”:“failed”,“reason”:“Timedout””
So the response is a string and not Json… no curly brackets.