0
votes

I'm writing a microservice in Play. I'd like my controller to be able to generate client errors (4xx) with a particular JSON response body. However, Play's default HttpErrorHandler kicks in, and replaces my response body with an HTML document.

How can I have my response returned to the client untouched?

I have looked into providing a custom HttpErrorHandler, but this doesn't give access to the response that my controller had generated; the signature is:

def onClientError(request: RequestHeader, statusCode: Int, message: String): Future[Result]

Edit: I can no longer reproduce this problem. Now, the error handler doesn't kick in -- which is the behaviour I'd expect. Most likely some form of user confusion / error.

1

1 Answers

1
votes

A client error is a condition which is caused by the client, and Play doesn't know how to handle. That includes malformed headers, non-existing resources (read : No route available for that path).

In all cases, this won't hit a controller : It's handled before it's routed. That also means there is no body that can be passed along.

If it does hit a controller, you're free to return a Result with the proper response code and body. If it doesn't hit a controller, and the error handler is invoked, you need to return a response based on the request itself.

An example of what you're trying to achieve would be handy, since it's a bi t unclear to me.