mapRouteResultPF

mapRouteResultPF

§Signature

§Description

Partial Function version of mapRouteResult.

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 allows to specify a partial function that doesn't have to handle all potential RouteResult instances.

See Transforming the RouteResult for similar directives.

§Example

  1. case object MyCustomRejection extends Rejection
  2. val rejectRejections = // not particularly useful directive
  3. mapRouteResultPF {
  4. case Rejected(_) => Rejected(List(AuthorizationFailedRejection))
  5. }
  6. val route =
  7. rejectRejections {
  8. reject(MyCustomRejection)
  9. }
  10.  
  11. // tests:
  12. Get("/") ~> route ~> check {
  13. rejection shouldEqual AuthorizationFailedRejection
  14. }