Skip to content

Bug/25 report invalid parameters as 400#29

Merged
edegenetais-nx merged 3 commits intomainfrom
bug/25_report_invalid_parameters_as_400
Jul 12, 2024
Merged

Bug/25 report invalid parameters as 400#29
edegenetais-nx merged 3 commits intomainfrom
bug/25_report_invalid_parameters_as_400

Conversation

@edegenetais-nx
Copy link
Copy Markdown
Contributor

Closes #25

@edegenetais-nx edegenetais-nx requested a review from bou3108 May 16, 2024 17:36
@edegenetais-nx edegenetais-nx self-assigned this May 16, 2024
@edegenetais-nx
Copy link
Copy Markdown
Contributor Author

@bou3108 : une fois n'est pas coutume, j'aurais besoin de feedback de ta part, particulièrement sur la partie 400 BAD_REQUEST pour les fichiers toggle malformés.

Comment on lines +40 to +50
public class DataProcessingExceptionHandler extends ResponseEntityExceptionHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(DataProcessingExceptionHandler.class);

@ExceptionHandler(value = DataProcessingException.class)
public final ResponseEntity handleAllExceptions(
DataProcessingException ex, WebRequest request) {
LOGGER.error("Invalid toggle file", ex);
return new ResponseEntity<>(new ErrorReport(ex.getMessage()), HttpStatus.BAD_REQUEST);
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je n'ai pas le réflexe d'utiliser les handlers !

Quel était le comportement précédent en cas d'erreur ? On renvoyait quoi au client ? Une 500 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui, on renvoyait une 500. Puisqu'on sait interrompre la requête avec retour d'erreur, autant faire un retour informatif.

Comment on lines +38 to +47
public class UnexpectedExceptionHandler extends ResponseEntityExceptionHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(UnexpectedExceptionHandler.class);

@ExceptionHandler(value = Throwable.class)
public final ResponseEntity handleAllExceptions(Throwable ex, WebRequest request) {
LOGGER.error("Unexpected error", ex);
return new ResponseEntity<>(new ErrorReport("Internal Server Error"), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si je comprends bien la logique,

  • on identifie toutes les erreurs donc on sait qu'elles sont liées à la requête
  • on les gère avec un code 400 et une information minimale dans le corps de la réponse
  • on gère un handleAll en dernier lieu avec un code 500 pour ce qui nous aurait échappé
  • on ne renvoie au client qu'un rapport d'erreur limité à timestamp + message de l'exception
  • on log côté serveur pour pouvoir retrouver l'info a posteriori an croisant avec le timestamp fourni par le client

C'est bien ça ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectivement, c'est ça. Double bénéfice attendu :

  • retour appelant plus clair (typologie d'erreurs)
  • moins de fuite d'info sur la stack

@edegenetais-nx edegenetais-nx merged commit 6461f95 into main Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid query parameters are reported as internal errors.

2 participants