Skip to content

Commit

Permalink
fix(api): Log urls fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Dec 4, 2023
1 parent 4f4b6a1 commit 66106d0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/src/utils/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const getFosmWorksByYear = async ({ results = [], options, pit, searchAfter }) =
},
};
const url = `${process.env.FOSM_URL}/_search`;
console.log(url);
return fetch(url, params)
.then((response) => {
if (response.ok) return response.json();
Expand Down Expand Up @@ -172,10 +173,14 @@ const getOpenAlexPublicationsByYear = (options, cursor = '*', previousResponse =
url += '&[email protected]';
}
url += '&select=authorships,display_name,doi,id,ids,publication_year,type&cursor=*';
console.log(`${url}&cursor=${cursor}`);
return fetch(`${url}&cursor=${cursor}`)
.then((response) => {
if (response.ok) return response.json();
if (response.status === 429) return new Promise((resolve) => setTimeout(resolve, 2000)).then(() => getOpenAlexPublicationsByYear(options, cursor, previousResponse));
if (response.status === 429) {
console.log('ERROR');
return new Promise((resolve) => setTimeout(resolve, 2000)).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 66106d0

Please sign in to comment.