I created my custom Exception ProduitIntrouvableException
which extends RuntimeException
@ResponseStatus(HttpStatus.NOT_FOUND)
public class ProduitIntrouvableException extends RuntimeException {
public ProduitIntrouvableException(String s) {
super(s);
}
}
and in my controller, I throw it when my p
is null
as follow
@RestController
public class ProductController {
@Autowired
private ProductDao productDao;
@GetMapping(value="/Produits/{id}")
public MappingJacksonValue afficherUnProduit(@PathVariable int id) throws ProduitIntrouvableException {
Product p = productDao.findById(id);
if(p==null)
throw new ProduitIntrouvableException("Le produit avec l'id "+id+" n'existe pas");
SimpleBeanPropertyFilter monFiltre = SimpleBeanPropertyFilter.serializeAllExcept("prixAchat","id");
FilterProvider listDeNosFiltres = new SimpleFilterProvider().addFilter("monFiltreDynamique", monFiltre);
MappingJacksonValue produitsFiltres = new MappingJacksonValue(p);
produitsFiltres.setFilters(listDeNosFiltres);
return produitsFiltres;
}
}
But I am getting an empty message as follow while I pass a String "product not found"
to the constructor but I don't why it is ignored
{
"timestamp": "2020-08-05T16:36:06.825+00:00",
"status": 404,
"error": "Not Found",
"message": "",
"path": "/Produits/40"
}
what can be the reason.
Spring Boot version: 2.3.2.RELEASE