Skip to content

Commit c7150c0

Browse files
committed
Retry when api fails
Signed-off-by: Jay Wang <[email protected]>
1 parent ef7ba0c commit c7150c0

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

src/components/author-list/author-list.ts

+9-17
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,20 @@ export class RecRecAuthorList extends LitElement {
8080
//==========================================================================||
8181
// Private Helpers ||
8282
//==========================================================================||
83-
async updateAuthorDetails() {
83+
async updateAuthorDetails(retry = 3) {
8484
if (this.authors.length === 0) {
8585
this.authorDetails = [];
8686
return;
8787
}
8888

89-
let done = false;
90-
let retry = 3;
91-
92-
while (!done && retry > 0) {
93-
try {
94-
const data = await searchAuthorDetails(
95-
this.authors.map(d => d.authorId)
96-
);
97-
this.authorDetails = data;
98-
done = true;
99-
} catch (e) {
100-
await new Promise<void>(resolve => {
101-
setTimeout(resolve, 2000);
102-
});
103-
retry -= 1;
104-
}
89+
try {
90+
const data = await searchAuthorDetails(this.authors.map(d => d.authorId));
91+
this.authorDetails = data;
92+
} catch (e) {
93+
await new Promise<void>(resolve => {
94+
setTimeout(resolve, 2000);
95+
});
96+
await this.updateAuthorDetails(retry - 1);
10597
}
10698
}
10799

src/components/author-view/author-view.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class RecRecAuthorView extends LitElement {
6464
//==========================================================================||
6565
// Event Handlers ||
6666
//==========================================================================||
67-
searchInput(e: InputEvent, delay = 200) {
67+
searchInput(e: InputEvent, delay = 600) {
6868
const target = e.currentTarget as HTMLInputElement;
6969
const query = target.value;
7070

src/components/recommender-view/recommender-view.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,22 @@ export class RecRecRecommenderView extends LitElement {
345345
return awardMap;
346346
}
347347

348-
async updateCitations() {
349-
console.time('Query citations');
350-
const paperCitations = await getPaperCitations([...this.selectedPaperIDs]);
351-
console.timeEnd('Query citations');
348+
async updateCitations(retry = 3) {
349+
let paperCitations: SemanticPaperCitationDetail[] = [];
350+
351+
try {
352+
console.time('Query citations');
353+
paperCitations = await getPaperCitations([...this.selectedPaperIDs]);
354+
console.timeEnd('Query citations');
355+
} catch (e) {
356+
await new Promise<void>(resolve =>
357+
setTimeout(() => {
358+
resolve();
359+
}, 1000)
360+
);
361+
await this.updateCitations(retry - 1);
362+
return;
363+
}
352364

353365
// Find and store collaborators
354366
for (const paper of this.papers) {

src/recrec-api/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default {
2626

2727
const newRequest = new Request(request, {
2828
headers: {
29-
...request.headers,
3029
'x-api-key': `${env.SEMANTIC_API}`,
3130
},
3231
body: request.body,

0 commit comments

Comments
 (0)