Spring RestController Better Error Handling

Instead of returning the plain old Java object in the mapping method, we can use return a ResponseEntity<T> object. For exmaple:

    @GetMapping("/")
    public ResponseEntity<Book> index() {
        try {
            Book b = bookService.editBookName(1);
            return ResponseEntity.ok(b);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.status(HttpStatus.CONFLICT).body(null);
        }
    }