Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use await instead of Promise, fixes tests #427

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions src/1edtech/biblio.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@ 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());
}
}
}
Loading