cancelRejections

cancelRejections

§Signature

§Description

Adds a TransformationRejection cancelling all rejections created by the inner route for which the condition argument function returns true.

See also cancelRejection, for canceling a specific rejection.

Read Rejections to learn more about rejections.

For more advanced handling of rejections refer to the handleRejections directive which provides a nicer DSL for building rejection handlers.

§Example

  1. def isMethodRejection: Rejection => Boolean = {
  2. case MethodRejection(_) => true
  3. case _ => false
  4. }
  5.  
  6. val route =
  7. cancelRejections(isMethodRejection) {
  8. post {
  9. complete("Result")
  10. }
  11. }
  12.  
  13. // tests:
  14. Get("/") ~> route ~> check {
  15. rejections shouldEqual Nil
  16. handled shouldEqual false
  17. }