From 565b480b2e4effecd49d5357891b6a42df5516bd Mon Sep 17 00:00:00 2001 From: 2beaucoup Date: Mon, 21 Dec 2015 15:19:38 +0100 Subject: [PATCH] =doc add custom ValidationRejection handling to samples --- .../scaladsl/server/RejectionHandlerExamplesSpec.scala | 3 +++ .../directives/ExecutionDirectivesExamplesSpec.scala | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/RejectionHandlerExamplesSpec.scala b/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/RejectionHandlerExamplesSpec.scala index 0cb36109f9..00c7551c82 100644 --- a/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/RejectionHandlerExamplesSpec.scala +++ b/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/RejectionHandlerExamplesSpec.scala @@ -25,6 +25,9 @@ object MyRejectionHandler { .handle { case AuthorizationFailedRejection ⇒ complete((Forbidden, "You're out of your depth!")) } + .handle { case ValidationRejection(msg, _) ⇒ + complete((InternalServerError, "That wasn't valid! " + msg)) + } .handleAll[MethodRejection] { methodRejections ⇒ val names = methodRejections.map(_.supported.name) complete((MethodNotAllowed, s"Can't do that! Supported: ${names mkString " or "}!")) diff --git a/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/directives/ExecutionDirectivesExamplesSpec.scala b/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/directives/ExecutionDirectivesExamplesSpec.scala index 60f22d8218..daafbdd7e6 100644 --- a/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/directives/ExecutionDirectivesExamplesSpec.scala +++ b/akka-docs-dev/rst/scala/code/docs/http/scaladsl/server/directives/ExecutionDirectivesExamplesSpec.scala @@ -32,11 +32,13 @@ class ExecutionDirectivesExamplesSpec extends RoutingSpec { "handleRejections" in { val totallyMissingHandler = RejectionHandler.newBuilder() .handleNotFound { complete((StatusCodes.NotFound, "Oh man, what you are looking for is long gone.")) } + .handle { case ValidationRejection(msg, _) => complete((StatusCodes.InternalServerError, msg)) } .result() val route = pathPrefix("handled") { handleRejections(totallyMissingHandler) { - path("existing")(complete("This path exists")) + path("existing")(complete("This path exists")) ~ + path("boom")(reject(new ValidationRejection("This didn't work."))) } } @@ -52,5 +54,9 @@ class ExecutionDirectivesExamplesSpec extends RoutingSpec { status shouldEqual StatusCodes.NotFound responseAs[String] shouldEqual "Oh man, what you are looking for is long gone." } + Get("/handled/boom") ~> route ~> check { + status shouldEqual StatusCodes.InternalServerError + responseAs[String] shouldEqual "This didn't work." + } } }