Suppose I am sending a complete JSON object in Postman like the below one for POST-end-point:
{
"student": [
{
"studentId" : "1234",
"feesPayment" : {
"amount" : 500.0,
"code" : "INR"
}
},
{
"studentId" : "5678",
"feesPayment" : {
"amount" : 500.0,
"code" : "INR"
}
}
]
}
then the status code is 200 OK
But now, I am sending the same JSON object but with some modification in the object like the below one for the same POST-end-point: (just removing the "feesPayment" object)
{
"student": [
{
"studentId" : "1234"
},
{
"studentId" : "5678"
}
]
}
then the status code is 500 Internal Server Error for obvious reasons and the error looks like the below one:
{
"timestamp" : "2021-09-02T17:07:31",
"status" : 500,
"error" : "Internal Server Error",
"message" : "Internal Server Error"
}
For this 500 status code, the error message is "Internal Server Error". So my question is How can I set this error message to something else like "Fee Payment Details are missing" instead of the default Internal Server Error message?
Approach/Code in Java and SpringBoot is appreciated.