From d43b3f2d86ccae3a227d4ef031b7697a3e50f3c3 Mon Sep 17 00:00:00 2001 From: Xavi Aracil Date: Fri, 3 Nov 2023 13:54:59 +0100 Subject: [PATCH 1/2] Use await instead of Promise, fixes tests --- src/1edtech/biblio.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/1edtech/biblio.js b/src/1edtech/biblio.js index 4e66a7aab2..a31a63263f 100644 --- a/src/1edtech/biblio.js +++ b/src/1edtech/biblio.js @@ -25,21 +25,19 @@ export async function run(conf) { if (!conf.disableFetchIMSbiblio) { // console.log("fetching ims biblio..."); - fetch(imsBiblioURL, { mode: "cors" }) - .then(response => { - if (response.ok) { - return response.json(); - } + try { + const response = await fetch(imsBiblioURL, { mode: "cors" }); + if (!response.ok) { throw new Error(response.statusText); - }) - .then(json => { - // TODO invalid json should be caught here - // JSON.stringify(conf.localBiblio) --> throws error? - // TODO we might want to worry about dupes and precedence - conf.localBiblio = Object.assign(conf.localBiblio, json); - }) - .catch(error => { - pub("warn", error.toString()); - }); + } + const json = await response.json(); + // TODO invalid json should be caught here + // JSON.stringify(conf.localBiblio) --> throws error? + // TODO we might want to worry about dupes and precedence + conf.localBiblio = Object.assign(conf.localBiblio, json); + } + catch (error) { + pub("warn", error.toString()); + } } } From 89cb3f303275d70ad42ea8b0e1fe2bc0c84a5f07 Mon Sep 17 00:00:00 2001 From: Xavi Aracil Date: Fri, 3 Nov 2023 13:58:10 +0100 Subject: [PATCH 2/2] Fixed linter error --- src/1edtech/biblio.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/1edtech/biblio.js b/src/1edtech/biblio.js index a31a63263f..9bbe85fa71 100644 --- a/src/1edtech/biblio.js +++ b/src/1edtech/biblio.js @@ -35,8 +35,7 @@ export async function run(conf) { // JSON.stringify(conf.localBiblio) --> throws error? // TODO we might want to worry about dupes and precedence conf.localBiblio = Object.assign(conf.localBiblio, json); - } - catch (error) { + } catch (error) { pub("warn", error.toString()); } }