Conversation
|
|
||
| private final HttpStatus status; | ||
| private final String messageKey; | ||
| private final Object[] messageArgs; |
There was a problem hiding this comment.
Au niveau de la classe AppException, on ne devrait pas se préoccuper de la langue des messages. Ces messages sont reçus en paramètres sous forme de String, sans qu'on ait besoin de se demander dans quelle langue ils sont.
There was a problem hiding this comment.
I moved this logic outside of AppException in an Interface
Localisation happens after going through the app layer in the web layer, from my understanding, and we have to pass those informations through the app layer so the web layer can use them or we end up having to fetch them from the web layer, mapping which exception correspond to which message before applying the localisation
Those are metadata and not the messages themeself which, from my understanding, can pass throug the app layer while following good practices
| public class GlobalExceptionHandler { | ||
|
|
||
| @Autowired | ||
| private MessageSource messageSource; |
There was a problem hiding this comment.
Comme pour la classe AppException, la classe GlobalExceptionHandler ne devrait pas avoir à se préoccuper du langage de l'utilisateur.
There was a problem hiding this comment.
GlobalExceptionHandler is in the web layer so It make sense for it to handle localisation but it's positon in the app folder seem misleading
Should I move it in a "web" folder instead ?
| */ | ||
| public record SignUpDto( | ||
| @NotBlank(message = "First name is required") | ||
| @NotBlank(message = "{validation.signup.firstName.required}") |
There was a problem hiding this comment.
Les messages de validation sont prédéfinis dans Spring, aussi bien en anglais qu'en français. Sauf si c'est un besoin spécifique, il ne faut pas définir de message personnalisé pour ces validations.
C'est valable pour toutes les validations dans toutes les DTO.
There was a problem hiding this comment.
I removed custome messages from dto
…in global AppException
Localised backend messages