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?
Open application.properties
and add the below line:
server.error.include-stacktrace=never
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With