SUPPORT-8897: Fix
This commit is contained in:
parent
ad9c1ef68f
commit
003aea9fb2
8 changed files with 39 additions and 130 deletions
|
|
@ -1,61 +0,0 @@
|
||||||
package ru.micord.ervu.error_handling;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Primary;
|
|
||||||
import org.springframework.context.support.MessageSourceAccessor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import ru.cg.webbpm.modules.core.app_info.api.mode.AppMode;
|
|
||||||
import ru.cg.webbpm.modules.core.error_handling.api.ProcessedWebException;
|
|
||||||
import ru.cg.webbpm.modules.core.error_handling.api.impl.UnknownExceptionHandler;
|
|
||||||
import ru.cg.webbpm.modules.core.runtime.api.MessageBundleUtils;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Primary
|
|
||||||
public class ErvuUnknownExceptionHandler extends UnknownExceptionHandler {
|
|
||||||
protected static final MessageSourceAccessor ERVU_MESSAGE_SOURCE = MessageBundleUtils.createAccessor("exception_handler_messages");
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProcessedWebException process(Throwable throwable) {
|
|
||||||
if (AppMode.mode() == AppMode.Mode.PROD) {
|
|
||||||
return new ProcessedWebException()
|
|
||||||
.addMessage(unknownErrorMessage());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Throwable lastThrowable = findLastCause(throwable);
|
|
||||||
String lastThrowableStackTrace = Arrays.toString(lastThrowable.getStackTrace());
|
|
||||||
String limitLastThrowableStackTrace = lastThrowableStackTrace.length() > MAX_STACK_TRACE_LENGTH
|
|
||||||
? lastThrowableStackTrace.substring(0, MAX_STACK_TRACE_LENGTH) + " ..."
|
|
||||||
: lastThrowableStackTrace;
|
|
||||||
return new ProcessedWebException()
|
|
||||||
.addMessage(findLastNotEmptyMessage(throwable))
|
|
||||||
.setCauseStackTrace(limitLastThrowableStackTrace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String unknownErrorMessage() {
|
|
||||||
return ERVU_MESSAGE_SOURCE.getMessage("ervu.error.unknown", new Object[] {});
|
|
||||||
}
|
|
||||||
|
|
||||||
private Throwable findLastCause(Throwable throwable) {
|
|
||||||
if (throwable.getCause() != null) {
|
|
||||||
return findLastCause(throwable.getCause());
|
|
||||||
}
|
|
||||||
return throwable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String findLastNotEmptyMessage(Throwable throwable) {
|
|
||||||
String message = throwable.getMessage();
|
|
||||||
if(throwable.getCause() != null) {
|
|
||||||
String nextMessage = findLastNotEmptyMessage(throwable.getCause());
|
|
||||||
if(!StringUtils.isEmpty(nextMessage)) {
|
|
||||||
message = nextMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
ervu.error.unknown=??????? ???????? ??????????. ??????????, ????????? ??????? ?????.
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
ervu.error.unknown=The system is temporarily unavailable. Please try again later.
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
error.unknown=Система временно недоступна. Пожалуйста, повторите попытку позже.
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
error.unknown=The system is temporarily unavailable. Please try again later.
|
||||||
|
|
@ -22,4 +22,13 @@ export class AuthenticationService {
|
||||||
public isAuthenticated(): boolean {
|
public isAuthenticated(): boolean {
|
||||||
return this.cookieService.get('webbpm.ervu-lkrp-fl') != null;
|
return this.cookieService.get('webbpm.ervu-lkrp-fl') != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public redirectToEsia() {
|
||||||
|
return this.http.get<string>("esia/url")
|
||||||
|
.toPromise()
|
||||||
|
.then(url => {
|
||||||
|
window.open(url, "_self");
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,15 +65,10 @@ export abstract class AuthGuard implements CanActivate {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return this.httpClient.get<string>("esia/url")
|
return this.authenticationService.redirectToEsia().catch((reason) => {
|
||||||
.toPromise()
|
console.error(reason);
|
||||||
.then(url => {
|
return false;
|
||||||
window.open(url, "_self");
|
});
|
||||||
return true;
|
|
||||||
}).catch((reason)=> {
|
|
||||||
console.error(reason);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}).catch((reason) => {
|
}).catch((reason) => {
|
||||||
console.error(reason);
|
console.error(reason);
|
||||||
|
|
|
||||||
|
|
@ -13,76 +13,42 @@ import {
|
||||||
} from "@webbpm/base-package";
|
} from "@webbpm/base-package";
|
||||||
import {Injectable} from "@angular/core";
|
import {Injectable} from "@angular/core";
|
||||||
import {Router} from "@angular/router";
|
import {Router} from "@angular/router";
|
||||||
import {Observable, throwError} from "rxjs";
|
import {from, Observable, throwError} from "rxjs";
|
||||||
import {catchError} from "rxjs/operators";
|
import {catchError, map} from "rxjs/operators";
|
||||||
import {ErvuHttpInterceptorUtils} from "../../../util/ErvuHttpInterceptorUtils";
|
import {ErvuHttpInterceptorUtils} from "../../../util/ErvuHttpInterceptorUtils";
|
||||||
|
import {AuthenticationService} from "../../security/authentication.service";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ErvuHttpSecurityErrorInterceptor extends HttpSecurityErrorInterceptor
|
export class ErvuHttpSecurityErrorInterceptor extends HttpSecurityErrorInterceptor
|
||||||
implements HttpInterceptor {
|
implements HttpInterceptor {
|
||||||
private router: Router;
|
private authService: AuthenticationService;
|
||||||
private _userService: UserService;
|
|
||||||
private _messagesService: MessagesService;
|
|
||||||
|
|
||||||
|
|
||||||
constructor(router: Router, messagesService: MessagesService, userService: UserService) {
|
constructor(router: Router, messagesService: MessagesService, userService: UserService,
|
||||||
|
authService: AuthenticationService) {
|
||||||
super(router, messagesService, userService);
|
super(router, messagesService, userService);
|
||||||
this.router = router;
|
this.authService = authService;
|
||||||
this._userService = userService;
|
|
||||||
this._messagesService = messagesService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
protected processErrorResponseData(error: HttpErrorResponse) {
|
||||||
|
|
||||||
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");
|
|
||||||
this.processErrorResponseDataErvu(error);
|
|
||||||
return throwError(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private processErrorResponseDataErvu(error: HttpErrorResponse) {
|
|
||||||
let errorResponse: ErrorResponse = ErvuHttpInterceptorUtils.getErrorResponseFromResponse(error);
|
let errorResponse: ErrorResponse = ErvuHttpInterceptorUtils.getErrorResponseFromResponse(error);
|
||||||
errorResponse.messages.forEach((errorMessage) => {
|
errorResponse.messages.forEach((errorMessage) => {
|
||||||
this._messagesService.error(errorMessage, errorResponse);
|
this.messagesService.error(errorMessage, errorResponse);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected processAuthError(req: HttpRequest<any>, next: HttpHandler,
|
||||||
|
error: any): Observable<HttpEvent<any>> {
|
||||||
|
if (this.authService.isAuthenticated()) {
|
||||||
|
return super.processAuthError(req, next, error);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return from(this.authService.redirectToEsia()).pipe(
|
||||||
|
map(() => null),
|
||||||
|
catchError((err) => {
|
||||||
|
throw err;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue