mapRouteResultWith

mapRouteResultWith

Signature

def mapRouteResultWith(f: RouteResult  Future[RouteResult]): Directive0 

Description

Changes the message the inner route sends to the responder.

The mapRouteResult directive is used as a building block for Custom Directives to transform the RouteResult coming back from the inner route. It's similar to the mapRouteResult directive but returning a Future instead of a result immediadly, which may be useful for longer running transformations.

See Transforming the RouteResult for similar directives.

Example

case object MyCustomRejection extends Rejection
val rejectRejections = // not particularly useful directive
  mapRouteResultWith { res =>
    res match {
      case Rejected(_) => Future(Rejected(List(AuthorizationFailedRejection)))
      case _           => Future(res)
    }
  }
val route =
  rejectRejections {
    reject(MyCustomRejection)
  }

// tests:
Get("/") ~> route ~> check {
  rejection shouldEqual AuthorizationFailedRejection
}

Contents