mapRejections

Transforms the list of rejections the inner route produced.

Signature

def mapRejections(f: List[Rejection]  List[Rejection]): Directive0 

Description

The mapRejections directive is used as a building block for Custom Directives to transform a list of rejections from the inner route to a new list of rejections.

See Directives transforming the response for similar directives.

Example

// ignore any rejections and replace them by AuthorizationFailedRejection
val replaceByAuthorizationFailed = mapRejections(_ => List(AuthorizationFailedRejection))
val route =
  replaceByAuthorizationFailed {
    path("abc")(complete("abc"))
  }

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