changed interceptor util to non class
This commit is contained in:
parent
bfd9a94650
commit
f1737cc206
@ -31,7 +31,7 @@ import {
|
|||||||
} from '@shared/components/dialog/entity-conflict-dialog/entity-conflict-dialog.component';
|
} from '@shared/components/dialog/entity-conflict-dialog/entity-conflict-dialog.component';
|
||||||
import { HasId } from '@shared/models/base-data';
|
import { HasId } from '@shared/models/base-data';
|
||||||
import { HasVersion } from '@shared/models/entity.models';
|
import { HasVersion } from '@shared/models/entity.models';
|
||||||
import { InterceptorUtil } from './interceptor.util';
|
import { getInterceptorConfig } from './interceptor.util';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class EntityConflictInterceptor implements HttpInterceptor {
|
export class EntityConflictInterceptor implements HttpInterceptor {
|
||||||
@ -61,8 +61,8 @@ export class EntityConflictInterceptor implements HttpInterceptor {
|
|||||||
next: HttpHandler,
|
next: HttpHandler,
|
||||||
error: HttpErrorResponse
|
error: HttpErrorResponse
|
||||||
): Observable<HttpEvent<unknown>> {
|
): Observable<HttpEvent<unknown>> {
|
||||||
if (InterceptorUtil.getConfig(request).ignoreVersionConflict) {
|
if (getInterceptorConfig(request).ignoreVersionConflict) {
|
||||||
return next.handle(this.updateRequestVersion(request));
|
return throwError(() => error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.openConflictDialog(request.body, error.error.message).pipe(
|
return this.openConflictDialog(request.body, error.error.message).pipe(
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import { ActionNotificationShow } from '@app/core/notification/notification.acti
|
|||||||
import { DialogService } from '@core/services/dialog.service';
|
import { DialogService } from '@core/services/dialog.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { parseHttpErrorMessage } from '@core/utils';
|
import { parseHttpErrorMessage } from '@core/utils';
|
||||||
import { InterceptorUtil } from './interceptor.util';
|
import { getInterceptorConfig } from './interceptor.util';
|
||||||
|
|
||||||
const tmpHeaders = {};
|
const tmpHeaders = {};
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ export class GlobalHttpInterceptor implements HttpInterceptor {
|
|||||||
|
|
||||||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||||
if (req.url.startsWith('/api/')) {
|
if (req.url.startsWith('/api/')) {
|
||||||
const config = InterceptorUtil.getConfig(req);
|
const config = getInterceptorConfig(req);
|
||||||
this.updateLoadingState(config, true);
|
this.updateLoadingState(config, true);
|
||||||
let observable$: Observable<HttpEvent<any>>;
|
let observable$: Observable<HttpEvent<any>>;
|
||||||
if (this.isTokenBasedAuthEntryPoint(req.url)) {
|
if (this.isTokenBasedAuthEntryPoint(req.url)) {
|
||||||
@ -94,7 +94,7 @@ export class GlobalHttpInterceptor implements HttpInterceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handleResponseError(req: HttpRequest<any>, next: HttpHandler, errorResponse: HttpErrorResponse): Observable<HttpEvent<any>> {
|
private handleResponseError(req: HttpRequest<any>, next: HttpHandler, errorResponse: HttpErrorResponse): Observable<HttpEvent<any>> {
|
||||||
const config = InterceptorUtil.getConfig(req);
|
const config = getInterceptorConfig(req);
|
||||||
let unhandled = false;
|
let unhandled = false;
|
||||||
const ignoreErrors = config.ignoreErrors;
|
const ignoreErrors = config.ignoreErrors;
|
||||||
const resendRequest = config.resendRequest;
|
const resendRequest = config.resendRequest;
|
||||||
|
|||||||
@ -18,32 +18,29 @@ import { HttpRequest } from '@angular/common/http';
|
|||||||
import { InterceptorConfig } from '@core/interceptors/interceptor-config';
|
import { InterceptorConfig } from '@core/interceptors/interceptor-config';
|
||||||
import { InterceptorHttpParams } from '@core/interceptors/interceptor-http-params';
|
import { InterceptorHttpParams } from '@core/interceptors/interceptor-http-params';
|
||||||
|
|
||||||
export class InterceptorUtil {
|
const internalUrlPrefixes = [
|
||||||
|
'/api/auth/token',
|
||||||
|
'/api/rpc'
|
||||||
|
];
|
||||||
|
|
||||||
private static readonly internalUrlPrefixes = [
|
export const getInterceptorConfig = (req: HttpRequest<unknown>): InterceptorConfig => {
|
||||||
'/api/auth/token',
|
let config: InterceptorConfig;
|
||||||
'/api/rpc'
|
if (req.params && req.params instanceof InterceptorHttpParams) {
|
||||||
];
|
config = (req.params as InterceptorHttpParams).interceptorConfig;
|
||||||
|
} else {
|
||||||
static getConfig(req: HttpRequest<unknown>): InterceptorConfig {
|
config = new InterceptorConfig();
|
||||||
let config: InterceptorConfig;
|
|
||||||
if (req.params && req.params instanceof InterceptorHttpParams) {
|
|
||||||
config = (req.params as InterceptorHttpParams).interceptorConfig;
|
|
||||||
} else {
|
|
||||||
config = new InterceptorConfig();
|
|
||||||
}
|
|
||||||
if (this.isInternalUrlPrefix(req.url)) {
|
|
||||||
config.ignoreLoading = true;
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
if (isInternalUrlPrefix(req.url)) {
|
||||||
private static isInternalUrlPrefix(url: string): boolean {
|
config.ignoreLoading = true;
|
||||||
for (const prefix of this.internalUrlPrefixes) {
|
|
||||||
if (url.startsWith(prefix)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
return config;
|
||||||
|
};
|
||||||
|
|
||||||
|
const isInternalUrlPrefix = (url: string): boolean => {
|
||||||
|
for (const prefix of internalUrlPrefixes) {
|
||||||
|
if (url.startsWith(prefix)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user