playframework - How to check for 200 OK response status using Scala and Play Framework -
i have following actor class responsible sending json message url using post.
import play.api.libs.ws._ class worker extends actor { val logger: logger = logger("superman") val supermanurl = "http://localhost:9000/superman/send" def receive = { case message: jsvalue => { val transactionid = (message \ "transactionid").get println("received json object =>" + message) val responsefromsuperman = ws.url(supermanurl).withheaders("content-type" -> "application/json").post(message) responsefromsuperman.map( result => { //todo: make sure log if response status 200 ok logger.info("""message="ack received superman" transactionid=""" + transactionid)} ).recover { case error: throwable => logger.error("""message="nack received superman" transactionid=""" + transactionid) + " errormessage:" + error.getlocalizedmessage() } } } } so, if todo above, add check response type 200 ok. current implementation not doing , logs message if manually send in badrequest. tried checking result.allheaders returns:
map(date -> buffer(wed, 27 jan 2016 21:45:31 gmt), content-type -> buffer(text/plain; charset=utf-8), content-length -> buffer(7))
but no information response status 200 ok
simply:
import play.api.http.status if(result.status == status.ok) { // ... }
Comments
Post a Comment