cancelRejections • Akka HTTP (original) (raw)

Signature

def cancelRejections(classes: Class[_]*): Directive0
def cancelRejections(cancelFilter: Rejection => Boolean): Directive0

Description

Adds a TransformationRejectionTransformationRejection 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

Scala

source`def isMethodRejection: Rejection => Boolean = { case MethodRejection(_) => true case _ => false }

val route = cancelRejections(isMethodRejection) { post { complete("Result") } }

// tests: Get("/") ~> route ~> check { rejections shouldEqual Nil handled shouldEqual false }`

Java

source`import static akka.http.javadsl.server.Directives.cancelRejections;

final Predicate isMethodRejection = p -> p instanceof MethodRejection; final Route route = cancelRejections( isMethodRejection, () -> post(() -> complete("Result")) );

// tests: runRouteUnSealed(route, HttpRequest.GET("/")) .assertRejections();`

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.