I have a spring-boot application which has the following end point:
@RequestMapping("/my-end-point")
public MyCustomObject handleProduct(
@RequestParam(name = "productId") String productId,
@RequestParam(name = "maxVersions", defaultValue = "1") int maxVersions,
){
// my code
}
This should handle requests of the form
/my-end-point?productId=xyz123&maxVersions=4
However, when I specify maxVersions=3.5
, this throws NumberFormatException
(for obvious reason). How can I gracefully handle this NumberFormatException
and return an error message?