Hi Alan,

yes, that's a valid use case. The route tree is usually traversed 
completely until a Route matches. But if you know that the search can be 
cut short, then `seal` is definitely a good solution. Another solution 
would be to use only `handleRejections` which would have the advantage that 
only rejections are handled and exceptions will still bubble up and run 
through the exception handlers you have defined further up in your route.

Johannes


On Tuesday, March 7, 2017 at 11:32:37 PM UTC+1, Alan Burlison wrote:
>
> I have an Akka HTTP route for a REST API that first checks the base path, 
> then  checks the user authentication is valid, adds some custom headers and 
> extracts the base URI before processing the sub-routes. However if the URL 
> doesn't match any of the sub-routes, request processing "rolls back" to the 
> authentication step and I get an incorrect message about authentication 
> failing.
> ​ ​
> ​I've wrapped the sub-route processing in Route.seal and that ​​means that 
> I​ now get a "Not Found" 
> ​for nonexistent paths, ​
> as required
> ​. However the documentation says that Route.seal ​
> ​shouldn't really be needed for application code. Is this a valid use of 
> Route.seal, or is there a better way to prevent route processing from 
> "rolling back" past a specified point?​
>
>
> def route: Route = {
>   pathPrefix("rest" / "v1") {
>     // If the request authenticates successfully, add the custom headers 
> to the response
>     // and extract the base URI we were called with.
>     (combinedAuth & respondWithHeaders(versionHeaders) & baseUri ) { 
> (sess, baseUri) => {
>      // Process valid sub-routes, seal the route so we don't roll back 
> past this point.
>       Route.seal(concat(
>         pathEndOrSingleSlash { topRoute(sess, baseUri) },
>         pathPrefix("users")  { userRoute(sess, baseUri) }
>       ))}
>     }
>   }
> }
>
> -- 
> Alan Burlison
> --
>

-- 
>>>>>>>>>>      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.

Reply via email to