Merge pull request #16949 from spray/wip-16835-mathias

Refactor akka.http.server.RejectionHandler
This commit is contained in:
Roland Kuhn 2015-02-27 14:11:52 +01:00
commit 70c6c1a246
9 changed files with 239 additions and 133 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) {