Project

General

Profile

« Previous | Next » 

Revision 61262

[Trunk | Library]:
1. timeout-interceptor.service.ts: Added whitelist, so that urls included in the list are not cut by this timeout interceptor.
2. services/reports.service.ts & landingPages/htmlProjectReport/htmlProjectReport.service.ts: In calls for CSV and HTML reports, added timeout 10 in seconds.
3. organization.component.ts: Created array "innerReportSubscriptions" where inner request of "downloading research results of a funder" are added - on error, all innerReportSubscriptions are unsubscribed.

View differences:

timeout-interceptor.service.ts
3 3
import { Observable } from 'rxjs';
4 4
import { timeout } from 'rxjs/operators';
5 5
import {isPlatformServer} from "@angular/common";
6
import {properties} from "../../environments/environment";
7
import {isArray} from "util";
6 8

  
7 9
export const DEFAULT_TIMEOUT = new InjectionToken<number>('defaultTimeout');
8 10

  
9 11
@Injectable()
10 12
export class TimeoutInterceptor implements HttpInterceptor {
13
  private static TIMEOUT_WHITELIST = [properties.csvAPIURL];
14

  
11 15
  constructor(@Inject(DEFAULT_TIMEOUT) protected defaultTimeout: number, @Inject(PLATFORM_ID) private platformId: any) {
12 16
  }
13 17

  
14 18
  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
15
    if (req.method !== 'GET') {
19
    if (req.method !== 'GET' || this.isService(req, TimeoutInterceptor.TIMEOUT_WHITELIST)) {
16 20
      return next.handle(req);
17 21
    }
18 22

  
......
20 24
    const timeoutValueNumeric = Number(timeoutValue);
21 25
    return next.handle(req).pipe(timeout(timeoutValueNumeric));
22 26
  }
27

  
28
  isService(req: HttpRequest<any>, service: string | string[]):boolean {
29
    if(isArray(service)) {
30
      return !!service.find(element => req.url.indexOf(element) !== -1);
31
    } else {
32
      return req.url.indexOf(service) !== -1;
33
    }
34
  }
23 35
}

Also available in: Unified diff