Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove "trace" field from ResponseStatusException

Tags:

spring-boot

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?

like image 385
Pabi Avatar asked Feb 22 '19 12:02

Pabi


1 Answers

Open application.properties and add the below line:

server.error.include-stacktrace=never 
like image 158
KimchiMan Avatar answered Sep 18 '22 14:09

KimchiMan