@swaheed wrote:
here is my route structure
classA { implicit def classARejectionHandler = RejectionHandler.newBuilder() .handle { case MissingCookieRejection(cookieName) => complete(HttpResponse(BadRequest, entity = "No cookies, no service!!!")) } .handle { case AuthorizationFailedRejection => complete((Forbidden, "You're out of your depth!")) } .handle { case ValidationRejection(msg, _) => complete((InternalServerError, "That wasn't valid! " + msg)) } .handleAll[MethodRejection] { methodRejections => val names = methodRejections.map(_.supported.name) complete((MethodNotAllowed, s"Can't do that! Supported: ${names mkString " or "}!")) } .handleNotFound { complete((NotFound, "Not here!")) } .result() val route:Route = handleRejections(classARejectionHandler) { concat( path("event-by-id") { get { } } , path("create-event") { post { } } } classB { implicit def classBRejectionHandler = RejectionHandler.newBuilder() .handle { case MissingCookieRejection(cookieName) => complete(HttpResponse(BadRequest, entity = "No cookies, no service!!!")) } .handle { case AuthorizationFailedRejection => complete((Forbidden, "You're out of your depth!")) } .handle { case ValidationRejection(msg, _) => complete((InternalServerError, "That wasn't valid! " + msg)) } .handleAll[MethodRejection] { methodRejections => val names = methodRejections.map(_.supported.name) complete((MethodNotAllowed, s"Can't do that! Supported: ${names mkString " or "}!")) } .handleNotFound { complete((NotFound, "Not here!")) } .result() val route:Route = handleRejections(classBRejectionHandler) { path("fileUploads") { post { } } } } class Demo extends App { def main { val a =new classA val b = new ClassB val routes = a~b val bindingFuture = Http().bindAndHandle(MainRouter.routes, hostName, port) } }
now the problem is when i hit the route
localhost:8080/fileuploads
with methodPOST
with its params the route works when
i remove the rejections from
classA
it works when i remove the rejection both from
classA
andclassB
route does not work when
the rejection code is present in both
classA
andclassB
classesonly in
classA
by does not work i means i get the response
Not here!
which is
classA
'shandleNotFound
rejection handler is rejecting the route ofclasssB
because i am hitting the route ofclassB
According to my understanding there is some problem in chaining the routes but i need to put different routes in different classes this is my requirement
how can i stop getting rejection of a desired route from other chained routes rejection handlers?
Posts: 5
Participants: 2