I am designing a POJO for custom error scenarios of my @RequestMapping methods.
Spring by default throws a HttpMessageNotReadableException if a POST is made without any body and returns the error response very nicely as something like this:
{
"timestamp": "2017-07-28T18:54:11.867+0000",
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
"message": "Required request body is missing: public org.springframework.http.ResponseEntity<some.package.name.SomeResponseClass> some.package.name.SomeControllerClass.someRequestMappingMethod(java.util.Map<java.lang.String, java.lang.String>, some.package.name.SomeRequestClass)",
"path": "/somepath/"
}
Similarly if validation for any field annotated with @Valid fails, it throws MethodArgumentNotValidException and returns the error response as:
{
"timestamp": "2017-07-28T17:23:53.102+0000",
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.web.bind.MethodArgumentNotValidException",
"errors": [
{
"codes": [
"NotNull.incident.someField",
"NotNull.someField",
"NotNull.java.lang.String",
"NotNull"
],
"arguments": [
{
"codes": [
"someObject.someField",
"someField"
],
"arguments": null,
"defaultMessage": "someField",
"code": "someField"
}
],
"defaultMessage": "someField is null",
"objectName": "someObject",
"field": "someField",
"rejectedValue": null,
"bindingFailure": false,
"code": "NotNull"
}
],
"message": "Validation failed for object='someObject'. Error count: 2",
"path": "/somepath/"
}
I an having an understanding that in either of the above case Spring must be returning a ResponseEntity object with headers and body wrapped in it.
And there must be a model class representing the body having fields like above i.e. timestamp, status, error etc. I just wished to visit that class to get an idea of what all fields Spring has included in their error response model. Or may be I might want to extend it. I have spent quite a huge amount of time by now searching for that class, but couldn't find.
The best I could find is ResponseEntityExceptionHandler#handleException(), but my debugger will not even go at the break-point set there!!
Can anyone point me to the package where it exists?