In a backend that has separate validation functions to verify the validity of the data, if this data is invalid the procedure (returning a 400 or printing something on the screen, for example) must occur in this validation part or is a task for the controller?
In the frontend where I have a part that takes care of the requests to the server (services), when an error of one of these requests is received, is the service or controller responsible for the user?
Whose responsibility?
simple example with php (the question is not focused on any language, just for example)
main.php:
//Forma 1
isValidPassword("123", "321");
//Forma 2
isValidPassword("123", "321") or die("senhas diferente");
validation.php:
//Forma 1
function isValidPassword($password, $confirm) {
$password === $confirm or die("senhas diferente");
}
//Forma 2
function isValidPassword($password, $confirm) {
return $password === $confirm;
}
In front of the idea is the same, execute a alert()
on the controller or the validation function?