In my spring controller I return a ResponseStatusException
if no entity is found, like this:
@GetMapping("/categories/{id}")
public ResponseEntity<Category> getCategoryById(@PathVariable(value = "id") String id) {
try {
return new ResponseEntity<Category>(categoryService.findById(id), HttpStatus.OK);
} catch (CategoryNotFoundException ex) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, ex.getMessage());
}
}
I would expect the answer to be something like:
{
"timestamp": "2019-02-22T12:25:29.913+0000",
"status": 404,
"error": "Not Found",
"message": "could not find category with ID: XYZ'.",
"path": "/categories/XYZ"
}
But the response also includes a long field "trace"
with the nested exception.
Is there a way to get rid of the trace field?
Seems the field "trace" is present if you have "spring-boot-devtools" in your dependencies. I do not see such traces in my outputs after excluding devtools.
Hope it will help.