SUPPORT-8897: Fix

This commit is contained in:
Eduard Tihomirov 2025-02-17 14:32:25 +03:00
parent 003aea9fb2
commit 07ac3afa1e
3 changed files with 8 additions and 33 deletions

View file

@ -6,22 +6,22 @@ import {
HttpRequest
} from "@angular/common/http";
import {
ErrorResponse,
ErrorResponse, HttpInterceptorUtils,
HttpSecurityErrorInterceptor,
MessagesService,
UserService
} from "@webbpm/base-package";
import {Injectable} from "@angular/core";
import {Router} from "@angular/router";
import {from, Observable, throwError} from "rxjs";
import {from, Observable} from "rxjs";
import {catchError, map} from "rxjs/operators";
import {ErvuHttpInterceptorUtils} from "../../../util/ErvuHttpInterceptorUtils";
import {AuthenticationService} from "../../security/authentication.service";
@Injectable()
export class ErvuHttpSecurityErrorInterceptor extends HttpSecurityErrorInterceptor
implements HttpInterceptor {
private authService: AuthenticationService;
private fallbackErrorMessage: string = "Система временно недоступна. Пожалуйста, повторите попытку позже";
constructor(router: Router, messagesService: MessagesService, userService: UserService,
@ -31,7 +31,7 @@ export class ErvuHttpSecurityErrorInterceptor extends HttpSecurityErrorIntercept
}
protected processErrorResponseData(error: HttpErrorResponse) {
let errorResponse: ErrorResponse = ErvuHttpInterceptorUtils.getErrorResponseFromResponse(error);
let errorResponse: ErrorResponse = HttpInterceptorUtils.getErrorResponseFromResponse(error, this.fallbackErrorMessage);
errorResponse.messages.forEach((errorMessage) => {
this.messagesService.error(errorMessage, errorResponse);
});

View file

@ -5,14 +5,16 @@ import {Router} from "@angular/router";
import {EMPTY, Observable} from "rxjs";
import {catchError} from "rxjs/operators";
import {ErvuHttpSecurityErrorInterceptor} from "./ervu-http-security-error-interceptor";
import {AuthenticationService} from "../../security/authentication.service";
@Injectable()
export class DevHttpSecurityErrorInterceptor extends ErvuHttpSecurityErrorInterceptor
implements HttpInterceptor {
constructor(router: Router, messagesService: MessagesService, userService: UserService) {
super(router, messagesService, userService);
constructor(router: Router, messagesService: MessagesService, userService: UserService,
authService: AuthenticationService) {
super(router, messagesService, userService, authService);
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

View file

@ -1,27 +0,0 @@
import {HttpErrorResponse} from "@angular/common/http";
import {ErrorResponse} from "@webbpm/base-package";
export class ErvuHttpInterceptorUtils {
public static fallbackErrorMessage: string = "Система временно недоступна. Пожалуйста, повторите попытку позже";
public static getErrorResponseFromResponse(response: HttpErrorResponse): ErrorResponse {
let responseJSONObject = null;
try {
responseJSONObject = response.error;
}
catch (e) {
//ignore json parse error
}
if (responseJSONObject && (responseJSONObject.key || responseJSONObject.messages)) {
return responseJSONObject;
}
let errorResponse: ErrorResponse = new ErrorResponse();
errorResponse.messages.push(ErvuHttpInterceptorUtils.fallbackErrorMessage);
return errorResponse;
}
}