mapInnerRoute

mapInnerRoute

§Signature

§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

  1. val completeWithInnerException =
  2. mapInnerRoute { route => ctx =>
  3. try {
  4. route(ctx)
  5. } catch {
  6. case NonFatal(e) => ctx.complete(s"Got ${e.getClass.getSimpleName} '${e.getMessage}'")
  7. }
  8. }
  9.  
  10. val route =
  11. completeWithInnerException {
  12. complete(throw new IllegalArgumentException("BLIP! BLOP! Everything broke"))
  13. }
  14.  
  15. // tests:
  16. Get("/") ~> route ~> check {
  17. responseAs[String] shouldEqual "Got IllegalArgumentException 'BLIP! BLOP! Everything broke'"
  18. }