mapInnerRoute

Changes the execution model of the inner route by wrapping it with arbitrary logic.

Signature

def mapInnerRoute(f: Route  Route): Directive0 

Description

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

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"))
  }

Get("/") ~> route ~> check {
  responseAs[String] === "Got IllegalArgumentException 'BLIP! BLOP! Everything broke'"
}