You should use exception mapper. Example:
@Provider
public class ValidationExceptionMapper implements ExceptionMapper<javax.validation.ConstraintViolationException> {
public Response toResponse(javax.validation.ConstraintViolationException cex) {
Error error = new Error();
error.setMessage("Whatever message you want to send to user. " + cex);
return Response.entity(error).status(400).build(); //400 - bad request seems to be good choice
}
}
where Error could be something like:
@XmlRootElement
public class Error{
private String message;
//getter and setter for message field
}
Then you'll get error message wrapped into XML.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…