Closed fankao closed 2 years ago
We'll create CartController.java in the com.packt.modern.api.controllers package and implement CartApi:
@RestController
public class CartController implements CartApi {
private static final Logger log = LoggerFactory.getLogger(CartsController.class);
@Override
public ResponseEntity<List<Item>> addCartItemsByCustomerId(String customerId, @Valid Item item) {
log.info("Request for customer ID: {}\nItem: {}",
customerId, item);
return ok(Collections.EMPTY_LIST);
}
@Override
public ResponseEntity<List<Cart>> getCartByCustomerId(String
customerId) {
throw new RuntimeException("Manual Exception thrown");
}
// Other method implementations (omitted)
}
Adding a Global Exception Handler
We just need to create a class for each of the AOS API interfaces and implement it