Revision 61263
Added by Konstantinos Triantafyllou over 2 years ago
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
[Library | Angular 11]: Merge changes from trunk