mapRouteResponsePF

Changes the message the inner route sends to the responder.

Signature

def mapRouteResponsePF(f: PartialFunction[Any, Any]): Directive0 

Description

The mapRouteResponsePF directive is used as a building block for Custom Directives to transform what the inner route sends to the responder (see The Responder Chain). It’s similar to the mapRouteResponse directive but allows to specify a partial function that doesn’t have to handle all the incoming response messages.

See Directives hooking into the responder chain for similar directives.

Example

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

Get("/") ~> route ~> check {
  rejection === AuthorizationFailedRejection
}