This documentation regards version 10.1, however the current version is 10.7.0.
mapInnerRoute
Description
Changes the execution model of the inner route by wrapping it with arbitrary logic.
The mapInnerRoute
directive is used as a building block for Custom Directives to replace the inner route with any other route. Usually, the returned route wraps the original one with custom execution logic.
Example
- Scala
-
source
val completeWithInnerException = mapInnerRoute { route => ctx => try { route(ctx) } catch { case NonFatal(e) => ctx.complete(s"Got ${e.getClass.getSimpleName} '${e.getMessage}'") } } val route = completeWithInnerException { complete(throw new IllegalArgumentException("BLIP! BLOP! Everything broke")) } // tests: Get("/") ~> route ~> check { responseAs[String] shouldEqual "Got IllegalArgumentException 'BLIP! BLOP! Everything broke'" }
- Java