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';
|
||||
import { HasId } from '@shared/models/base-data';
|
||||
import { HasVersion } from '@shared/models/entity.models';
|
||||
import { InterceptorUtil } from './interceptor.util';
|
||||
import { getInterceptorConfig } from './interceptor.util';
|
||||
|
||||
@Injectable()
|
||||
export class EntityConflictInterceptor implements HttpInterceptor {
|
||||
@ -61,8 +61,8 @@ export class EntityConflictInterceptor implements HttpInterceptor {
|
||||
next: HttpHandler,
|
||||
error: HttpErrorResponse
|
||||
): Observable<HttpEvent<unknown>> {
|
||||
if (InterceptorUtil.getConfig(request).ignoreVersionConflict) {
|
||||
return next.handle(this.updateRequestVersion(request));
|
||||
if (getInterceptorConfig(request).ignoreVersionConflict) {
|
||||
return throwError(() => error);
|
||||
}
|
||||
|
||||
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 { TranslateService } from '@ngx-translate/core';
|
||||
import { parseHttpErrorMessage } from '@core/utils';
|
||||
import { InterceptorUtil } from './interceptor.util';
|
||||
import { getInterceptorConfig } from './interceptor.util';
|
||||
|
||||
const tmpHeaders = {};
|
||||
|
||||
@ -50,7 +50,7 @@ export class GlobalHttpInterceptor implements HttpInterceptor {
|
||||
|
||||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
if (req.url.startsWith('/api/')) {
|
||||
const config = InterceptorUtil.getConfig(req);
|
||||
const config = getInterceptorConfig(req);
|
||||
this.updateLoadingState(config, true);
|
||||
let observable$: Observable<HttpEvent<any>>;
|
||||
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>> {
|
||||
const config = InterceptorUtil.getConfig(req);
|
||||
const config = getInterceptorConfig(req);
|
||||
let unhandled = false;
|
||||
const ignoreErrors = config.ignoreErrors;
|
||||
const resendRequest = config.resendRequest;
|
||||
|
||||
@ -18,32 +18,29 @@ import { HttpRequest } from '@angular/common/http';
|
||||
import { InterceptorConfig } from '@core/interceptors/interceptor-config';
|
||||
import { InterceptorHttpParams } from '@core/interceptors/interceptor-http-params';
|
||||
|
||||
export class InterceptorUtil {
|
||||
const internalUrlPrefixes = [
|
||||
'/api/auth/token',
|
||||
'/api/rpc'
|
||||
];
|
||||
|
||||
private static readonly internalUrlPrefixes = [
|
||||
'/api/auth/token',
|
||||
'/api/rpc'
|
||||
];
|
||||
|
||||
static getConfig(req: HttpRequest<unknown>): 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;
|
||||
export const getInterceptorConfig = (req: HttpRequest<unknown>): InterceptorConfig => {
|
||||
let config: InterceptorConfig;
|
||||
if (req.params && req.params instanceof InterceptorHttpParams) {
|
||||
config = (req.params as InterceptorHttpParams).interceptorConfig;
|
||||
} else {
|
||||
config = new InterceptorConfig();
|
||||
}
|
||||
|
||||
private static isInternalUrlPrefix(url: string): boolean {
|
||||
for (const prefix of this.internalUrlPrefixes) {
|
||||
if (url.startsWith(prefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (isInternalUrlPrefix(req.url)) {
|
||||
config.ignoreLoading = true;
|
||||
}
|
||||
}
|
||||
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