SUPPORT-8848: Fix

This commit is contained in:
Eduard Tihomirov 2025-02-04 09:40:45 +03:00
parent 0485296824
commit 485d3f962f
4 changed files with 82 additions and 7 deletions

View file

@ -1,14 +1,14 @@
import {HTTP_INTERCEPTORS} from "@angular/common/http";
import {
FormDirtyInterceptor,
HttpSecurityErrorInterceptor,
HttpSecurityInterceptor
} from "@webbpm/base-package";
import {AbsoluteUrlCsrfInterceptor} from "./absolute-url-csrf.interceptor";
import {ErvuHttpSecurityErrorInterceptor} from "./ervu-http-security-error-interceptor";
export const DEFAULT_HTTP_INTERCEPTOR_PROVIDERS = [
{provide: HTTP_INTERCEPTORS, useClass: HttpSecurityInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: HttpSecurityErrorInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: ErvuHttpSecurityErrorInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: FormDirtyInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: AbsoluteUrlCsrfInterceptor, multi: true}
];

View file

@ -2,10 +2,11 @@ import {HTTP_INTERCEPTORS} from "@angular/common/http";
import {FormDirtyInterceptor, HttpSecurityInterceptor} from "@webbpm/base-package";
import {DevHttpSecurityErrorInterceptor} from "./http-security-error-interceptor.dev";
import {AbsoluteUrlCsrfInterceptor} from "./absolute-url-csrf.interceptor";
import {ErvuHttpSecurityErrorInterceptor} from "./ervu-http-security-error-interceptor";
export const DEFAULT_HTTP_INTERCEPTOR_PROVIDERS = [
{provide: HTTP_INTERCEPTORS, useClass: HttpSecurityInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: DevHttpSecurityErrorInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: ErvuHttpSecurityErrorInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: FormDirtyInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: AbsoluteUrlCsrfInterceptor, multi: true},
];

View file

@ -0,0 +1,75 @@
import {
HttpEvent,
HttpHandler,
HttpInterceptor,
HttpRequest
} from "@angular/common/http";
import {
HttpSecurityErrorInterceptor,
MessagesService,
UserService
} from "@webbpm/base-package";
import {Injectable} from "@angular/core";
import {Router} from "@angular/router";
import {Observable, throwError} from "rxjs";
import {catchError} from "rxjs/operators";
@Injectable()
export class ErvuHttpSecurityErrorInterceptor extends HttpSecurityErrorInterceptor
implements HttpInterceptor {
private router: Router;
private _userService: UserService;
constructor(router: Router, messagesService: MessagesService, userService: UserService) {
super(router, messagesService, userService);
this.router = router;
this._userService = userService;
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (req.headers.has("Error-intercept-skip")) {
let isSkipped: string = req.headers.get("Error-intercept-skip");
req.headers.delete("Error-intercept-skip");
if (isSkipped == "true") {
return next.handle(req);
}
}
return next.handle(req).pipe(catchError(error => {
switch (error.status) {
case 401: {
window.location.reload();
break;
}
case 419:
case 440: {
console.log(
"Logout redirect applied due to response status " + error.status +
" received by HTTP Interceptor"
);
this._userService.clearSessionStore();
return throwError(error);
}
case 403: {
console.log(
"Access-Denied redirect applied due to response status " + error.status
+ " received by HTTP Interceptor"
);
this.router.navigateByUrl('/access-denied');
return throwError(error);
}
case 422: {
console.log("Error " + error.status + " server response received by HTTP Interceptor");
return throwError(error);
}
default: {
this._userService.hideProgressBar();
console.log("Error " + error.status + " server response received by HTTP Interceptor");
return throwError(error);
}
}
}));
}
}

View file

@ -1,19 +1,18 @@
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
import {HttpSecurityErrorInterceptor, MessagesService, UserService} from "@webbpm/base-package";
import {MessagesService, UserService} from "@webbpm/base-package";
import {Injectable} from "@angular/core";
import {Router} from "@angular/router";
import {EMPTY, Observable} from "rxjs";
import {catchError} from "rxjs/operators";
import {ErvuHttpSecurityErrorInterceptor} from "./ervu-http-security-error-interceptor";
@Injectable()
export class DevHttpSecurityErrorInterceptor extends HttpSecurityErrorInterceptor
export class DevHttpSecurityErrorInterceptor extends ErvuHttpSecurityErrorInterceptor
implements HttpInterceptor {
private router: Router;
constructor(router: Router, messagesService: MessagesService, userService: UserService) {
super(router, messagesService, userService);
this.router = router;
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {