diff --git a/ui-ngx/src/app/core/interceptors/entity-conflict.interceptor.ts b/ui-ngx/src/app/core/interceptors/entity-conflict.interceptor.ts index e97aa67fd7..18890874c0 100644 --- a/ui-ngx/src/app/core/interceptors/entity-conflict.interceptor.ts +++ b/ui-ngx/src/app/core/interceptors/entity-conflict.interceptor.ts @@ -29,16 +29,15 @@ import { MatDialog } from '@angular/material/dialog'; import { EntityConflictDialogComponent } from '@shared/components/dialog/entity-conflict-dialog/entity-conflict-dialog.component'; -import { InterceptorConfigService } from '@core/services/interceptor-config.service'; import { HasId } from '@shared/models/base-data'; import { HasVersion } from '@shared/models/entity.models'; +import { InterceptorUtil } from '@core/utils/interceptor.util'; @Injectable() export class EntityConflictInterceptor implements HttpInterceptor { constructor( private dialog: MatDialog, - private interceptorConfigService: InterceptorConfigService ) {} intercept(request: HttpRequest, next: HttpHandler): Observable> { @@ -62,11 +61,11 @@ export class EntityConflictInterceptor implements HttpInterceptor { next: HttpHandler, error: HttpErrorResponse ): Observable> { - if (this.interceptorConfigService.getInterceptorConfig(request).ignoreVersionConflict) { + if (InterceptorUtil.getConfig(request).ignoreVersionConflict) { return next.handle(this.updateRequestVersion(request)); } - return this.openConflictDialog(request, error.error.message).pipe( + return this.openConflictDialog(request.body, error.error.message).pipe( switchMap(result => { if (result) { return next.handle(this.updateRequestVersion(request)); @@ -81,9 +80,9 @@ export class EntityConflictInterceptor implements HttpInterceptor { return request.clone({ body }); } - private openConflictDialog(request: HttpRequest, message: string): Observable { + private openConflictDialog(entity: unknown & HasId & HasVersion, message: string): Observable { const dialogRef = this.dialog.open(EntityConflictDialogComponent, { - data: { message, entity: request.body } + data: { message, entity } }); return dialogRef.afterClosed(); diff --git a/ui-ngx/src/app/core/interceptors/global-http-interceptor.ts b/ui-ngx/src/app/core/interceptors/global-http-interceptor.ts index 6023267ff9..d74d159851 100644 --- a/ui-ngx/src/app/core/interceptors/global-http-interceptor.ts +++ b/ui-ngx/src/app/core/interceptors/global-http-interceptor.ts @@ -29,7 +29,7 @@ import { ActionNotificationShow } from '@app/core/notification/notification.acti import { DialogService } from '@core/services/dialog.service'; import { TranslateService } from '@ngx-translate/core'; import { parseHttpErrorMessage } from '@core/utils'; -import { InterceptorConfigService } from '@core/services/interceptor-config.service'; +import { InterceptorUtil } from '@core/interceptors/interceptor.util'; const tmpHeaders = {}; @@ -46,12 +46,11 @@ export class GlobalHttpInterceptor implements HttpInterceptor { private dialogService: DialogService, private translate: TranslateService, private authService: AuthService, - private interceptorConfigService: InterceptorConfigService ) {} intercept(req: HttpRequest, next: HttpHandler): Observable> { if (req.url.startsWith('/api/')) { - const config = this.interceptorConfigService.getInterceptorConfig(req); + const config = InterceptorUtil.getConfig(req); this.updateLoadingState(config, true); let observable$: Observable>; if (this.isTokenBasedAuthEntryPoint(req.url)) { @@ -95,7 +94,7 @@ export class GlobalHttpInterceptor implements HttpInterceptor { } private handleResponseError(req: HttpRequest, next: HttpHandler, errorResponse: HttpErrorResponse): Observable> { - const config = this.interceptorConfigService.getInterceptorConfig(req); + const config = InterceptorUtil.getConfig(req); let unhandled = false; const ignoreErrors = config.ignoreErrors; const resendRequest = config.resendRequest; diff --git a/ui-ngx/src/app/core/services/interceptor-config.service.ts b/ui-ngx/src/app/core/interceptors/interceptor.util.ts similarity index 82% rename from ui-ngx/src/app/core/services/interceptor-config.service.ts rename to ui-ngx/src/app/core/interceptors/interceptor.util.ts index a5e4d39cec..5f4a651219 100644 --- a/ui-ngx/src/app/core/services/interceptor-config.service.ts +++ b/ui-ngx/src/app/core/interceptors/interceptor.util.ts @@ -14,22 +14,17 @@ /// limitations under the License. /// -import { Injectable } from '@angular/core'; import { HttpRequest } from '@angular/common/http'; import { InterceptorConfig } from '@core/interceptors/interceptor-config'; import { InterceptorHttpParams } from '@core/interceptors/interceptor-http-params'; -@Injectable({ - providedIn: 'root' -}) -export class InterceptorConfigService { - - private readonly internalUrlPrefixes = [ +export class InterceptorUtil { + private static readonly internalUrlPrefixes = [ '/api/auth/token', '/api/rpc' ]; - getInterceptorConfig(req: HttpRequest): InterceptorConfig { + static getConfig(req: HttpRequest): InterceptorConfig { let config: InterceptorConfig; if (req.params && req.params instanceof InterceptorHttpParams) { config = (req.params as InterceptorHttpParams).interceptorConfig; @@ -42,7 +37,7 @@ export class InterceptorConfigService { return config; } - private isInternalUrlPrefix(url: string): boolean { + private static isInternalUrlPrefix(url: string): boolean { for (const prefix of this.internalUrlPrefixes) { if (url.startsWith(prefix)) { return true;