Skip to content

Commit 1bc66fa

Browse files
vins01-4scienceatarix83
authored andcommitted
[UXP-98] Adds delay for poll requests
1 parent 9300269 commit 1bc66fa

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

src/app/submission/sections/unpaywall/submission-section-unpaywall.component.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Store } from '@ngrx/store';
99
import { SubmissionState } from '../../submission.reducers';
1010
import {
1111
catchError,
12+
delay,
1213
distinctUntilChanged,
1314
filter,
1415
last,
@@ -166,24 +167,30 @@ export class SubmissionSectionUnpaywallComponent extends SectionModelComponent i
166167
.pipe(
167168
switchMap(sections => {
168169
let unpaywall = this.extractUnpaywallSection(sections);
169-
if (unpaywall.status !== UnpaywallSectionStatus.PENDING) {
170+
if (unpaywall != null && unpaywall.status !== UnpaywallSectionStatus.PENDING) {
170171
return of(unpaywall);
171172
} else {
172-
return this.patchForRefresh(false).pipe(
173-
pollWhile(
174-
API_CHECK_INTERVAL,
175-
res => this.isStillPending(res),
176-
MAX_TRIES
177-
),
178-
takeUntil(this.stopFetch$),
179-
this.getUnpaywallSection(),
180-
catchError(err => {
181-
this.notificationsService.error(err?.message);
182-
return of(Object.assign({}, {
183-
...this.unpaywallSection$.getValue(),
184-
status: UnpaywallSectionStatus.NO_FILE
185-
}));
186-
})
173+
return of(false).pipe(
174+
delay(API_CHECK_INTERVAL),
175+
switchMap(refresh => this.patchForRefresh(refresh)
176+
.pipe(
177+
pollWhile(
178+
API_CHECK_INTERVAL,
179+
res => this.isStillPending(res),
180+
MAX_TRIES
181+
),
182+
takeUntil(this.stopFetch$),
183+
this.getUnpaywallSection(),
184+
catchError(err => {
185+
this.stopFetch$.next();
186+
this.notificationsService.error(err?.message);
187+
return of(Object.assign({}, {
188+
...this.unpaywallSection$.getValue(),
189+
status: UnpaywallSectionStatus.NOT_FOUND
190+
}));
191+
})
192+
)
193+
)
187194
);
188195
}
189196
})

0 commit comments

Comments
 (0)