Skip to content

Commit

Permalink
fix(api): Manage OpenAlex 429 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Nov 30, 2023
1 parent 8bd688c commit 3af153e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/src/routes/works.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ router.route('/works')
// Deduplicate publications by ids
const deduplicatedWorks = deduplicateWorks(works);
console.timeEnd(`2. Dedup ${options.affiliations}`);
// Goup by affiliations
// Compute distinct affiliations of works
console.time(`3. GroupBy ${options.affiliations}`);
const uniqueAffiliations = groupByAffiliations({ options, works: deduplicatedWorks });
console.timeEnd(`3. GroupBy ${options.affiliations}`);
Expand Down
1 change: 1 addition & 0 deletions server/src/utils/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const getOpenAlexPublicationsByYear = (options, cursor = '*', previousResponse =
return fetch(`${url}&cursor=${cursor}`)
.then((response) => {
if (response.ok) return response.json();
if (response.status === 429) return new Promise((resolve) => setTimeout(resolve, 100)).then(() => getOpenAlexPublicationsByYear(options, cursor, previousResponse));
console.error(`Error while fetching ${url} :`);
console.error(`${response.status} | ${response.statusText}`);
return 'Oops... OpenAlex API request did not work';
Expand Down

0 comments on commit 3af153e

Please sign in to comment.