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 ([email protected]) 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 [email protected]. To post to this group, send email to [email protected]. 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
