mardi 5 octobre 2021

Log if the response was successful or not

I have this lines of code in the first entry point to my backend application and I want to find out if the request was successful or not so I can log it. What would be the best way to do this, without affecting my logic? With a try/catch or to check that with an if/else?

   List<People>  getPeopleFromCity = cityService.getPeopleFromCity (language, city);
      
    return ResponseEntity.ok(getPeopleFromCity);

What I was thinking is something like:

List<People>  getPeopleFromCity = null;
try {
  getPeopleFromCity = cityService.getPeopleFromCity (language, city);
log.info("The getPeopleFromCity  request is susscesful")
} catch (Exception e) {
  e.printStackTrace();
log.info("The getPeopleFromCity  request is failed")
}

return ResponseEntity.ok(getPeopleFromCity);

Or with an if/else?

Aucun commentaire:

Enregistrer un commentaire