diff options
Diffstat (limited to 'src/app/http-interceptors/loading-indicator.interceptor.ts')
-rw-r--r-- | src/app/http-interceptors/loading-indicator.interceptor.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/app/http-interceptors/loading-indicator.interceptor.ts b/src/app/http-interceptors/loading-indicator.interceptor.ts new file mode 100644 index 0000000..d48d04f --- /dev/null +++ b/src/app/http-interceptors/loading-indicator.interceptor.ts @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022. Deutsche Telekom AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + + +import { Injectable } from '@angular/core'; +import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { finalize } from 'rxjs/operators'; +import { LoadingIndicatorService } from 'src/app/services/loading-indicator.service'; + +@Injectable() +export class LoadingIndicatorInterceptor implements HttpInterceptor { + readonly excludedUrls = ['preferences', 'actions']; + + constructor(private readonly loadingIndicator: LoadingIndicatorService) {} + + intercept(req: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { + if (this.excludedUrls.some(url => req.url.includes(url))) { + return next.handle(req); + } + + this.loadingIndicator.show(); + return next.handle(req).pipe(finalize(() => this.loadingIndicator.hide())); + + } +} |