I would like to have a customized message for the HTTP response i.e.
{
"timestamp": "2020-06-30T00:40:58.558+00:00",
"status": 417,
"error": "Expectation Failed",
"message": "",
"path": "/test/v1/tests/4ae767e1-ae83-66dd-9180-81160f766d90"
}
Instead of the above message, I want a customized "message":
{
"timestamp": "2020-06-30T00:40:58.558+00:00",
"status": 417,
"error": "Expectation Failed",
"message": "#/test: 8.0 is not higher or equal to 100",
"path": "/test/v1/tests/4ae767e1-ae83-66dd-9180-81160f766d90"
}
Here is my exception class:
@ResponseStatus(value = HttpStatus.EXPECTATION_FAILED)
public class ThrowError extends Exception {
private static final long serialVersionUID = 1L;
public ThrowErrorMessage(String message){
super(message);
}
Here is the catch block of a function in the controller:
catch(Exception e)
{
//basically I want e.getMessage() to be the value of the "Message" key
throw new ThrowErrorMessage(e.getMessage());
}