Bug/25 report invalid parameters as 400#29
Merged
edegenetais-nx merged 3 commits intomainfrom Jul 12, 2024
Merged
Conversation
added 3 commits
May 16, 2024 19:32
…cted errors to it. Added benefit : less inforamtion leak about the server.
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. |
bou3108
approved these changes
May 17, 2024
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); | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
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 ?
Contributor
Author
There was a problem hiding this comment.
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); | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
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 ?
Contributor
Author
There was a problem hiding this comment.
Effectivement, c'est ça. Double bénéfice attendu :
- retour appelant plus clair (typologie d'erreurs)
- moins de fuite d'info sur la stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #25