In my last project, there was a requirement for throwing exceptions when the request body contains extra parameters.
If the request will be like
{
"test":"body",
"name":"HR 1",
"location":"Location"
}
where test parameter is unnecessary and I've to return a response that should be like
{
"timestamp": "2022-05-07T00:13:59.144657",
"status": "500",
"error": "Internal Server Error",
"message": "test : must not be provided",
"path": "/api/departments/HR"
}
I've shared the answer. How I handled it.