How to map and use Play's (or HTTP) status codes to Lagom?

Lagom provides various exceptions for the below HTTP status codes -
400, 403, 404, 405, 406, 413, 415, 500, 503

Apart from the above codes, we had used 409 (Conflict) and 422 (Unprocessable) in our (previous) Play application. How should we cleanly use Lagom’s exception handling and not trip the circuit breaker?

Right now, we are only using BadRequest and NotFound and have white-listed these two in the web-gateway application.conf project.

You need to create own ConflictException extending TransportException and implement exception serializer. Something like this

public class MyExceptionSerializer extends JacksonExceptionSerializer {

    public MyExceptionSerializer() {
        super(new Environment(Mode.PROD));
    }

    @Override
    public Throwable deserialize(RawExceptionMessage message) {
        Throwable throwable = super.deserialize(message);
        if (throwable instanceof TransportException && ((TransportException)throwable).errorCode().http() == 409) {
            return new ConflictException();
        }
        return throwable;
    }
}

And don’t forget to add ConflictException to white-list of CB.