I am running Scala version 2.11.1 and Scalatra version 2.3.0 and had a strange problem that plain vanilla halt does not work when the trait JacksonJsonSupport
is mixed in with my controller class. Here are two simpel code snippets to illustrate the problem.
Snippet 1: Halt works
import org.scalatra._ import scalate.ScalateSupport import org.json4s.{ DefaultFormats, Formats } import org.scalatra.json._ class RestController extends ScalatraresttestStack { protected implicit val jsonFormats: Formats = DefaultFormats get("/v1/search") { "Here #1" } get("/v2/search") { halt(502) } }
Snippet 2: Halt does not work
import org.scalatra._ import scalate.ScalateSupport import org.json4s.{ DefaultFormats, Formats } import org.scalatra.json._ class RestController extends ScalatraresttestStack with JacksonJsonSupport { protected implicit val jsonFormats: Formats = DefaultFormats get("/v1/search") { "Here #1" } get("/v2/search") { halt(502) } }
After further investigation it turns out that halt will work if the the body and reason parameters are set, for example changing halt(502)
to:
halt(status = 502, body = "Expected error occured", reason = "Really?")
Does work. Why is it that it will only work if the other two parameters are set when the trait JacksonJsonSupport
is mixed in? Has anyone else experienced this problem?