!htp #16835 Refactor RejectionHandler infrastructure for cleanliness and independence from rejection ordering

This commit is contained in:
Mathias 2015-02-26 15:08:06 +01:00
parent a4f4cb298a
commit 9c3124f344
7 changed files with 220 additions and 119 deletions

View file

@ -18,10 +18,12 @@ object MyRejectionHandler {
import StatusCodes._
import Directives._
implicit val myRejectionHandler = RejectionHandler {
case MissingCookieRejection(cookieName) :: _ =>
complete(HttpResponse(BadRequest, entity = "No cookies, no service!!!"))
}
implicit val myRejectionHandler = RejectionHandler.newBuilder()
.handle {
case MissingCookieRejection(cookieName) =>
complete(HttpResponse(BadRequest, entity = "No cookies, no service!!!"))
}
.result()
object MyApp {
implicit val system = ActorSystem()

View file

@ -29,10 +29,9 @@ class ExecutionDirectivesExamplesSpec extends RoutingSpec {
}
}
"handleRejections" in {
val totallyMissingHandler = RejectionHandler {
case Nil /* secret code for path not found */ =>
complete(StatusCodes.NotFound, "Oh man, what you are looking for is long gone.")
}
val totallyMissingHandler = RejectionHandler.newBuilder()
.handleNotFound { complete(StatusCodes.NotFound, "Oh man, what you are looking for is long gone.") }
.result()
val route =
pathPrefix("handled") {
handleRejections(totallyMissingHandler) {