Commit 6f7aa68c authored by Yogi_Wang's avatar Yogi_Wang
Browse files

[fix][unauthorized] Support show relogin when unauthorized in popup modal


1.support show relogin when unauthorized  in popup modali
2.change change member role error handle
3.change helm chart service error handle
Signed-off-by: default avatarYogi_Wang <yawang@vmware.com>
parent 6db856c3
......@@ -51,6 +51,19 @@ export class MessageHandlerService implements ErrorHandler {
}
}
}
public handleErrorPopupUnauthorized(error: any | string): void {
if (!(error.statusCode || error.status)) {
return;
}
let msg = errorHandler(error);
let code = error.statusCode || error.status;
if (code === httpStatusCode.Unauthorized) {
this.msgService.announceAppLevelMessage(code, msg, AlertType.DANGER);
// Session is invalid now, clare session cache
this.session.clear();
}
}
public handleReadOnly(): void {
this.msgService.announceAppLevelMessage(503, 'REPO_READ_ONLY', AlertType.WARNING);
......
......@@ -5,6 +5,7 @@ import { EditQuotaQuotaInterface } from '../../../../services';
import { HarborLibraryModule } from '../../../../harbor-library.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CURRENT_BASE_HREF } from "../../../../utils/utils";
import { ErrorHandler } from '../../../../utils/error-handler';
describe('EditProjectQuotasComponent', () => {
let component: EditProjectQuotasComponent;
......@@ -27,6 +28,7 @@ describe('EditProjectQuotasComponent', () => {
],
providers: [
{ provide: SERVICE_CONFIG, useValue: config },
ErrorHandler
]
})
.compileComponents();
......
......@@ -15,8 +15,8 @@ import { Component, Output, EventEmitter } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";
import { errorHandler } from "../../utils/shared/shared.utils";
// tslint:disable-next-line:no-unused-variable
import { Observable, Subscription } from "rxjs";
import { ErrorHandler } from "../../../lib/utils/error-handler";
@Component({
selector: "hbr-inline-alert",
......@@ -36,7 +36,9 @@ export class InlineAlertComponent {
@Output() confirmEvt = new EventEmitter<boolean>();
constructor(private translate: TranslateService) {}
constructor(private translate: TranslateService,
private errHandler: ErrorHandler,
) {}
public get errorMessage(): string {
return this.displayedText;
......@@ -50,6 +52,7 @@ export class InlineAlertComponent {
.get(this.displayedText)
.subscribe((res: string) => (this.displayedText = res));
}
this.errHandler.handleErrorPopupUnauthorized(error);
this.inlineAlertType = "danger";
this.showCancelAction = false;
......
......@@ -6,6 +6,7 @@ import { InlineAlertComponent } from '../inline-alert/inline-alert.component';
import { SERVICE_CONFIG, IServiceConfig } from '../../entities/service.config';
import { SharedModule } from '../../utils/shared/shared.module';
import { ErrorHandler } from '../../../lib/utils/error-handler';
describe('PushImageButtonComponent (inline template)', () => {
let component: PushImageButtonComponent;
......@@ -19,7 +20,8 @@ describe('PushImageButtonComponent (inline template)', () => {
],
declarations: [InlineAlertComponent, CopyInputComponent, PushImageButtonComponent],
providers: [
{ provide: SERVICE_CONFIG, useValue: {} }
{ provide: SERVICE_CONFIG, useValue: {} },
ErrorHandler
]
});
......
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { DebugElement, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { SharedModule } from '../../utils/shared/shared.module';
......@@ -155,6 +155,7 @@ describe('Replication Component (inline template)', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
imports: [
SharedModule,
NoopAnimationsModule,
......
......@@ -47,6 +47,8 @@ export abstract class ErrorHandler {
* @memberOf ErrorHandler
*/
abstract log(log: any): void;
abstract handleErrorPopupUnauthorized(error: any): void;
}
@Injectable()
......@@ -67,4 +69,7 @@ export class DefaultErrorHandler extends ErrorHandler {
public log(log: any): void {
console.log("[Default log handler]: ", log);
}
public handleErrorPopupUnauthorized(error: any): void {
console.log("[Default log handler]: ", error);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment