====== Spring RestController Better Error Handling ====== Instead of returning the plain old Java object in the mapping method, we can use return a ResponseEntity object. For exmaple: @GetMapping("/") public ResponseEntity index() { try { Book b = bookService.editBookName(1); return ResponseEntity.ok(b); } catch (Exception e) { e.printStackTrace(); return ResponseEntity.status(HttpStatus.CONFLICT).body(null); } }