Fetch request coded catch clause tested
Signed-off-by: Eoghan Conlon <eoghanconlon73@skynet.ie>
This commit is contained in:
parent
114ad8ea36
commit
de2dc0b459
1 changed files with 30 additions and 1 deletions
|
@ -28,7 +28,36 @@
|
||||||
listener.preventDefault();
|
listener.preventDefault();
|
||||||
const formData = new FormData(formEl);
|
const formData = new FormData(formEl);
|
||||||
const object = { user: formData.get('user'), email: formData.get('mail')};
|
const object = { user: formData.get('user'), email: formData.get('mail')};
|
||||||
alert(JSON.stringify(object));
|
fetch('https://api.account.skynet.ie/ldap/recover/ssh/request', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(object),
|
||||||
|
mode: "cors"
|
||||||
|
})
|
||||||
|
.then(status)
|
||||||
|
.then(json)
|
||||||
|
.catch(() => {
|
||||||
|
document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function status(res){
|
||||||
|
if(res.status === 200){
|
||||||
|
return res.json();
|
||||||
|
} else if (res.status === 500){
|
||||||
|
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
|
||||||
|
} else {
|
||||||
|
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function json(temp){
|
||||||
|
if(temp){
|
||||||
|
if(temp.result === 'error'){
|
||||||
|
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`;
|
||||||
|
} else {
|
||||||
|
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Add table
Reference in a new issue