title: How to check for 200 OK response status using Scala and Play Framework
body: <p>I have a following Actor class that is responsible for sending a JSON message to a URL using <code>POST</code>.</p>
  
  <pre><code>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 =&gt; {
        val transactionID = (message \ "transactionID").get
        println("Received JSON Object =&gt;" + message)
        val responseFromSuperman = WS.url(supermanURL).withHeaders("Content-Type" -&gt; "application/json").post(message)
  
        responseFromSuperman.map(
          result =&gt; {
  
            //TODO: Make sure to only log if response status is 200 OK
  
            logger.info("""Message="ACK received from Superman" for transactionID=""" + transactionID)}
        ).recover { case error: Throwable =&gt;
          logger.error("""Message="NACK received from Superman" for transactionID=""" + transactionID) + " errorMessage:" + error.getLocalizedMessage()
        }
      }
  
    }
  
  }
  </code></pre>
  
  <p>So, if you look into my <code>TODO</code> above, I would like to add a check for a response type 200 OK. The current implementation is not doing that and it logs the message even if I manually send in a <code>BadRequest</code>. I tried checking for <code>result.allHeaders</code> which returns:</p>
  
  <p><code>Map(Date -&gt; Buffer(Wed, 27 Jan 2016 21:45:31 GMT), Content-Type -&gt; Buffer(text/plain; charset=utf-8), Content-Length -&gt; Buffer(7))</code> </p>
  
  <p>but no information about response status <code>200 OK</code></p>