From c825f588aeeef344df63cf21b9a709420653a6b9 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Thu, 9 Mar 2023 18:26:23 +0100 Subject: [PATCH] [Client] Refactor API JavaScript code Add documentation on functions and remove debug logging --- truthinquiry/static/js/api.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/truthinquiry/static/js/api.js b/truthinquiry/static/js/api.js index f589678..f55f986 100644 --- a/truthinquiry/static/js/api.js +++ b/truthinquiry/static/js/api.js @@ -1,3 +1,11 @@ +/** + * Make a request to the given endpoint of the API with the given body. + * + * @param {String} endpoint the endpoint on which make an API request + * @param {Object} body an object to send in the API request (this object can be omitted) + * @returns a Promise, which resolves when the server can be reached and responds without an error + * and rejects otherwise + */ async function makeAPIRequest(endpoint, body) { return new Promise((resolve, reject) => { const fetchOptions = { @@ -7,7 +15,6 @@ async function makeAPIRequest(endpoint, body) { fetch("/api/v1/" + endpoint, fetchOptions).then(response => { const responseCode = response.status; - console.log(responseCode); if (responseCode >= 500) { reject("Error " + responseCode + " when fetching " + endpoint); alert("Une réponse invalide du serveur a été obtenue, veuillez réessayer ultérieurement.");