Thanks!!
      I finally realized this
                

val route = pathPrefix("auth") {
  path("signIn") {
    post {
      entity(as[LoginPassword]) { loginPassword =>
        val token = signIn(loginPassword.login, loginPassword.password)
        val response = token.map(_ match {
          case Some(token) => prepareHttpResponse(StatusCodes.OK, 
token.asJson.toString)
          case None => prepareHttpResponse(StatusCodes.Unauthorized, "{reason: 
\"not found\"")
        })
        complete(response)
      }
    }
  }



More detail 
in: 
https://stackoverflow.com/questions/46856140/how-to-validate-complete-in-akka-http

El viernes, 20 de octubre de 2017, 17:19:28 (UTC-3), Konrad Malawski 
escribió:
>
> Don’t return null in scala code, that’s very not-scala-style.
> Instead you could return empty things, or best rather even to throw an 
> exception and make your handler
>
> https://doc.akka.io/docs/akka-http/current/scala/http/routing-dsl/exception-handling.html
>  make 
> it into a not found response.
>
> -- 
> Cheers,
> Konrad 'ktoso <http://kto.so>' Malawski
> Akka <http://akka.io/> @ Lightbend <http://lightbend.com/>
>
> On October 20, 2017 at 15:15:42, Samuel Heredia (heredia...@gmail.com 
> <javascript:>) wrote:
>
> Hi! , I have a Route where if a function finds a data in the DB responds a 
> value of type Json,
> when it does not find the value it responds with null and therefore the 
> complete responds null. 
> I want to validate this so that it does not respond null, but a String 
> that says: "Not found", this is my route, any help? Thanks
>
> val route = pathPrefix("auth") {
>   path("signIn") {
>     pathEndOrSingleSlash {
>       post {
>         entity(as[LoginPassword]) { loginPassword =>
>           val a = signIn(loginPassword.login, 
> loginPassword.password).map(_.asJson)
>            if(signIn(loginPassword.login, 
> loginPassword.password).map(_.asJson) == null){
>              complete(states.map(_.asJson))
>            }else {
>              def getObject : Option[Any] = Option(signIn(loginPassword.login, 
> loginPassword.password).map(_.asJson))
>              val ahh = signIn(loginPassword.login, 
> loginPassword.password).map(_.asJson)
>              if(getObject.isEmpty || getObject == null){ ///////NOT FOUND
>                complete("Not Found")
>              }else {
>                complete(complete(signIn(loginPassword.login, 
> loginPassword.password).map(_.asJson))
>              }
>              //complete(signIn(loginPassword.login, 
> loginPassword.password).map(_.asJson))
>            }
>         }
>       }
>     }
>   } 
>
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: 
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups 
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to akka-user+...@googlegroups.com <javascript:>.
> To post to this group, send email to akka...@googlegroups.com 
> <javascript:>.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to