scala - How to change HTTP status code of AsyncResult using Scalatra -


i have created simple controller (the code below obfuscated , simplified, assume ask returns future message). trying change http code other 200 (based on actor result).

when executing code below see result come expected, 200 instead of 404

   get("/:id") {         new asyncresult() {           val is: future[_] = ask(actor, message)(timeout.tomillis)           is.oncomplete { res =>             res match {               case success(result:any) => notfound(result) //not found example of different http code other 200           }        }     } 

another attempt was

case success(result:any) => {    this.status_ = (404)    result } 

in case, receive nullpointerexception because response (httpservletresponse) null, due fact response on separate thread.

tl;dr

how can 1 conditionally change http code of asyncresult/future in scalatra?

details

scala 2.11.6

scalatra 2.3.0

akka 2.3.9

after digging in scalatra futuresupport mixin, found:

implicit val response: httpservletresponse = scalatracontext.response 

defined member of asyncresult allows me change status code of http request inside oncomplete callback.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -