@@ -9,6 +9,7 @@ import { Store } from '@ngrx/store';
99import { SubmissionState } from '../../submission.reducers' ;
1010import {
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