add error adduser

This commit is contained in:
Valentin CZERYBA 2022-08-12 22:31:04 +02:00
parent c1248b0363
commit 1e7704a1ab
2 changed files with 44 additions and 13 deletions

View File

@ -118,6 +118,30 @@
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<div class="alert alert-warning alert-dismissible hidden" id="notModifiedAlert" role="alert">
<div>Utilisateur non modifié</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-danger alert-dismissible hidden" id="notModifiedAlert" role="alert">
<div>Action non autorisée</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-danger alert-dismissible hidden" id="forbiddenAlert" role="alert">
<div>Action interdite</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-danger alert-dismissible hidden" id="internalServerAlert" role="alert">
<div>Erreur interne du serveur</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="alert alert-danger alert-dismissible hidden" id="unknownAlert" role="alert">
<div>Erreur inconnue</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">

View File

@ -46,28 +46,35 @@ document.getElementById("addUser").addEventListener("click", function(){
withCredentials: true,
data: dataPut
}).then(function(response){
var idAlert = "";
switch(response.status){
case 200:
case 201:
location.reload();
break;
case 204:
console.log("Aucun contenu");
break;
case 401:
console.log("non autorisé");
break;
case 403:
console.log("interdit");
break;
case 500:
console.log("erreur interne");
idAlert="notModified"
break;
default:
console.log("error inconnue");
idAlert="unknown";
break
}
document.getElementById(idAlert+"Alert").classList.remove("hidden");
}).catch(function(error){
console.log(error);
switch(error.status){
case 401:
idAlert="notAuthorized";
break;
case 403:
idAlert="forbidden";
break;
case 500:
idAlert="internalServer";
break;
default:
idAlert="unknown";
break;
}
document.getElementById(idAlert+"Alert").classList.remove("hidden");
});
}