Dear all,
I have a route with a custom (global) implicit exceptionHandler that handles deserialisation errors in order to provide my spray-json POSTing users with enhanced feedback about what may be wrong with their payloads:
implicit def exceptionHandler(
implicit
settings: RoutingSettings,
log: LoggingContext
): ExceptionHandler = ExceptionHandler {
... a bunch of other things ....
case e: DeserializationException => ctx => {
log.warning(s"Received bad payload: ${ctx.request}")
ctx.reject(MalformedRequestContentRejection(e.getMessage()))
}
}
and this seems to work fine in my specs (using ScalaMock to mock out the backend)
"give a sensible error when given a bad payload" in {
val store = stub[BackendThing]
val message = "expected more from life"
(store.addPayload _).when(*).returns(
Future.failed(new DeserializationException(message))
)
val payload = """{"hello": "world"}""".parseJson.asJsObject
Post(s"/event/$name", payload) ~> route ~> check {
rejection shouldBe MalformedRequestContentRejection(message)
}
}
(this is passing).
BUT when I use the same route in my server, the log comes out like this
WARN - Received bad payload: HttpRequest(POST,HIDDEN,List(Remote-Address: HIDDEN, Remote-Ip-Port: HIDDEN, User-Agent: curl/7.38.0, Host: HIDDEN, user: sam-testing, Content-Type: application/json, Content-Length: 2),HttpEntity(application/json,{}),HTTP/1.1)
[error] 06 May 15 11:17:48.181 HttpServerConnection akka://MDES/user/IO-UHTTP/listener-0/0 [ MDES-akka.actor.default-dispatcher-2] WARN - Illegal response Rejected(List(MalformedRequestContentRejection(deserialising MyEntry: missing pricingGroup, found ,None))) to POST request to 'HIDDEN'
[info] 06 May 15 11:17:48.183 ResponseReceiverRef akka://MDES/temp/$a [ MDES-akka.actor.default-dispatcher-4] DEBUG - unhandled message from Actor[akka://MDES/user/monitor/uhttp/
10.4.4.152:51131#-2079242463]: Rejected(List(MalformedRequestContentRejection(deserialising MyEntry: missing pricingGroup, found ,None)))
so it looks like my log message is printed (via the implicit ActorSystem's LoggingContext), but then the HttpServerConnection doesn't like the Rejected message.
I'm using spray 1.3.3 on scala 2.11 and I have the HTTP IO actor provided by wandoulab's WebSockets (because this same actor system is used for WebSockets comms).
Any ideas?
I don't have a custom RejectionHandler.
Best regards,
Sam