1

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

Bashir
  • 2,057
  • 5
  • 19
  • 44

1 Answers1

3

From Spring Boot 2.3 Release Notes:

The error message and any binding errors are no longer included in the default error page by default. This reduces the risk of leaking information to a client. server.error.include-message and server.error.include-binding-errors can be used to control the inclusion of the message and binding errors respectively. Supported values are always, on-param, and never.

sp00m
  • 47,968
  • 31
  • 142
  • 252