Merge pull request #16949 from spray/wip-16835-mathias
Refactor akka.http.server.RejectionHandler
This commit is contained in:
commit
70c6c1a246
9 changed files with 239 additions and 133 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue