Spring Boot - Exception Handling
Consider this code snippet:
What is the likely problem if the client always receives HTTP 500 instead of 404 when a product is missing?
@ResponseStatus(HttpStatus.NOT_FOUND)
public class ProductNotFoundException extends RuntimeException {
public ProductNotFoundException(Long id) {
super("Product " + id + " not found");
}
}
@GetMapping("/products/{id}")
public Product getProduct(@PathVariable Long id) {
return productRepo.findById(id).orElseThrow(() -> new ProductNotFoundException(id));
}What is the likely problem if the client always receives HTTP 500 instead of 404 when a product is missing?
