In case of error, the simplest thing to begin with is to indicate an error message telling us what went wrong, especially in case of a bad input request or business validations since the client (or requestor) may have no idea of what went wrong. For example, in the preceding case, the NOT_FOUND status code is returned, But no other details are supplied.
Spring provides interesting notations such as ExceptionHandler and ControllerAdvice to handle this error. Let's see how this works.
Secondly, the service method earlier was directly manipulating the ResponseEntity by sending HTTP codes. We will revert it back to return business objects such as Product instead of ResponseEntity, making it more POJO-like. Revert ...