Hi have a simple spring controller that returns ResponseStatusException in case of error.
@RestController
@RequestMapping("/process")
public class ProcessWorkitemController {
@Autowired MyService service;
@GetMapping("/{id}")
public ResponseEntity<?> findById(@PathVariable Long id) {
Optional<MyObj> opt = service.getObj(id);
opt.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Process id %s not found", id), null));
return ResponseEntity.ok(opt.get());
}
}
This works perfctely if invoked with SoapUI: it shows me a Json as follows:
{
"timestamp": "2021-01-20T10:59:48.082+0000",
"status": 404,
"error": "Not Found",
"message": "Process id 1 not found",
"path": "/workspace-manager/process/1"
}
When I call the same service with the browser it shows the whitelabel error page with my custmo error message.
I want a JSON as response even on the browser, is this possible?
Thanks in advance.