!htc #16494 provide content negotiation fallback to exception handlers

This commit is contained in:
2beaucoup 2014-12-10 12:35:50 +01:00 committed by André Rüdiger
parent a1d7c33663
commit ec7156698a
7 changed files with 45 additions and 6 deletions

View file

@ -5,7 +5,8 @@
package akka.http.server
package directives
import akka.http.model.StatusCodes
import akka.http.model.{ MediaTypes, MediaRanges, StatusCodes }
import akka.http.model.headers._
import scala.concurrent.Future
@ -72,6 +73,27 @@ class ExecutionDirectivesSpec extends RoutingSpec {
responseAs[String] shouldEqual "There was an internal server error."
}
}
"always fall back to a default content type" in {
Get("/abc") ~> Accept(MediaTypes.`application/json`) ~>
get {
handleExceptions(handler) {
throw new RuntimeException
}
} ~> check {
status shouldEqual StatusCodes.InternalServerError
responseAs[String] shouldEqual "There was an internal server error."
}
Get("/abc") ~> Accept(MediaTypes.`text/xml`, MediaRanges.`*/*`.withQValue(0f)) ~>
get {
handleExceptions(handler) {
throw new RuntimeException
}
} ~> check {
status shouldEqual StatusCodes.InternalServerError
responseAs[String] shouldEqual "There was an internal server error."
}
}
}
def exceptionShouldBeHandled(route: Route) =