From de2dc0b4590458117a162871307d5d91782a889d Mon Sep 17 00:00:00 2001 From: Eoghan Conlon Date: Sun, 27 Aug 2023 21:36:30 +0100 Subject: [PATCH] Fetch request coded catch clause tested Signed-off-by: Eoghan Conlon --- src/recovery/ssh-request.html | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/recovery/ssh-request.html b/src/recovery/ssh-request.html index bf93aae..31afe18 100644 --- a/src/recovery/ssh-request.html +++ b/src/recovery/ssh-request.html @@ -28,7 +28,36 @@ listener.preventDefault(); const formData = new FormData(formEl); 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 = "Please try again"; + }); + } + + function status(res){ + if(res.status === 200){ + return res.json(); + } else if (res.status === 500){ + document.getElementById('formStatus').innerHTML = "Failure"; + } else { + document.getElementById('formStatus').innerHTML = "Failure: Failed to communicate to server"; + } + } + + function json(temp){ + if(temp){ + if(temp.result === 'error'){ + document.getElementById('formStatus').innerHTML = `${temp.error}`; + } else { + document.getElementById('formStatus').innerHTML = "Success"; + } + } }