September 2019
Intermediate to advanced
668 pages
15h 59m
English
API implementations use the exceptions in the util project to signal errors. They will be reported back to the REST client as HTTPS status codes indicating what went wrong. For example, the Product microservice implementation class, ProductServiceImpl.java, uses the InvalidInputException exception to return an error that indicates invalid input, as well as the NotFoundException exception to tell us that the product that was asked for does not exist. The code looks as follows:
if (productId < 1) throw new InvalidInputException("Invalid productId: " + productId);if (productId == 13) throw new NotFoundException("No product found for productId: " + productId);