title: How to change HTTP status code of AsyncResult using Scalatra
body: <p>I have created a simple controller (the code below is obfuscated and simplified, assume ask returns a future with a message).  What I am trying to do is change the HTTP code from something other than 200 (based on the actor result).</p>
  
  <p>When executing the code below I see the result come back as expected, but with 200 instead of 404</p>
  
  <pre><code>   get("/:id") {
          new AsyncResult() {
            val is: Future[_] = ask(actor, message)(timeout.toMillis)
            is.onComplete { res =&gt;
              res match {
                case Success(result:Any) =&gt; NotFound(result) //Not found is just an example of a different HTTP code other than 200
            }
         }
      }
  </code></pre>
  
  <p>another attempt was</p>
  
  <pre><code>case Success(result:Any) =&gt; {
     this.status_ = (404)
     result
  }
  </code></pre>
  
  <p>In this case, I receive a NullPointerException because the <code>response</code> (HTTPServletResponse) is null, due to the fact that the response is on a separate thread.</p>
  
  <p><strong>TL;DR</strong>  </p>
  
  <p>How can one conditionally change the HTTP code of an AsyncResult/Future in Scalatra?</p>
  
  <p><strong>Details</strong></p>
  
  <p>Scala 2.11.6</p>
  
  <p>Scalatra 2.3.0</p>
  
  <p>Akka 2.3.9</p>