Change request mode specified as API acquisition

change request mode specified as API acquisition.

Signed-off-by: Yogi_Wang <yawang@vmware.com>
This commit is contained in:
Yogi_Wang 2019-04-30 15:32:47 +08:00
parent 17b38e395a
commit a6e1ff33be
18 changed files with 170 additions and 160 deletions

View File

@ -53,6 +53,9 @@ export class GcComponent implements OnInit {
this.gcRepoService.getSchedule().subscribe(schedule => { this.gcRepoService.getSchedule().subscribe(schedule => {
this.initSchedule(schedule); this.initSchedule(schedule);
this.loadingGcStatus.emit(false); this.loadingGcStatus.emit(false);
}, error => {
this.errorHandler.error(error);
this.loadingGcStatus.emit(false);
}); });
} }

View File

@ -90,6 +90,9 @@ export class VulnerabilityConfigComponent implements OnInit {
this.initSchedule(schedule); this.initSchedule(schedule);
this.onGoing = false; this.onGoing = false;
this.loadingStatus.emit(this.onGoing); this.loadingStatus.emit(this.onGoing);
}, error => {
this.errorHandler.error(error);
this.loadingStatus.emit(this.onGoing);
}); });
} }

View File

@ -40,6 +40,7 @@ import {
import { CreateEditEndpointComponent } from "../create-edit-endpoint/create-edit-endpoint.component"; import { CreateEditEndpointComponent } from "../create-edit-endpoint/create-edit-endpoint.component";
import { CustomComparator } from "../utils"; import { CustomComparator } from "../utils";
import { errorHandler as errorHandFn } from "../shared/shared.utils";
import { operateChanges, OperateInfo, OperationState } from "../operation/operate"; import { operateChanges, OperateInfo, OperationState } from "../operation/operate";
import { OperationService } from "../operation/operation.service"; import { OperationService } from "../operation/operation.service";
@ -210,15 +211,11 @@ export class EndpointComponent implements OnInit, OnDestroy {
}); });
}) })
, catchError(error => { , catchError(error => {
if (error && error._body) { const message = errorHandFn(error);
const message = JSON.parse(error._body).message; this.translateService.get(message).subscribe(res =>
operateChanges(operMessage, OperationState.failure, message); operateChanges(operMessage, OperationState.failure, res)
);
return observableThrowError(message); return observableThrowError(message);
} else {
return this.translateService.get('BATCH.DELETED_FAILURE').pipe(map(res => {
operateChanges(operMessage, OperationState.failure, res);
}));
}
} }
)); ));
} }

View File

@ -35,6 +35,7 @@ import { ConfirmationDialogComponent } from "../confirmation-dialog/confirmation
import { operateChanges, OperateInfo, OperationState } from "../operation/operate"; import { operateChanges, OperateInfo, OperationState } from "../operation/operate";
import { OperationService } from "../operation/operation.service"; import { OperationService } from "../operation/operation.service";
import { map, catchError } from "rxjs/operators"; import { map, catchError } from "rxjs/operators";
import { errorHandler as errorHandFn } from "../shared/shared.utils";
import { Observable, throwError as observableThrowError, forkJoin } from "rxjs"; import { Observable, throwError as observableThrowError, forkJoin } from "rxjs";
@Component({ @Component({
selector: "hbr-label", selector: "hbr-label",
@ -163,9 +164,11 @@ export class LabelComponent implements OnInit {
operateChanges(operMessage, OperationState.success); operateChanges(operMessage, OperationState.success);
}); });
}), catchError(error => { }), catchError(error => {
return this.translateService.get('BATCH.DELETED_FAILURE').pipe(map(res => { const message = errorHandFn(error);
operateChanges(operMessage, OperationState.failure, res); this.translateService.get(message).subscribe(res =>
})); operateChanges(operMessage, OperationState.failure, res)
);
return observableThrowError(message);
})); }));
} }

View File

@ -46,6 +46,8 @@ import { ErrorHandler } from "../error-handler/error-handler";
import { CustomComparator } from "../utils"; import { CustomComparator } from "../utils";
import { operateChanges, OperateInfo, OperationState } from "../operation/operate"; import { operateChanges, OperateInfo, OperationState } from "../operation/operate";
import { OperationService } from "../operation/operation.service"; import { OperationService } from "../operation/operation.service";
import { errorHandler as errorHandFn } from "../shared/shared.utils";
const jobstatus = "InProgress"; const jobstatus = "InProgress";
@Component({ @Component({
@ -221,17 +223,11 @@ export class ListReplicationRuleComponent implements OnInit, OnChanges {
.subscribe(res => operateChanges(operMessage, OperationState.success)); .subscribe(res => operateChanges(operMessage, OperationState.success));
}) })
, catchError(error => { , catchError(error => {
if (error && error._body) { const message = errorHandFn(error);
const message = JSON.parse(error._body).message; this.translateService.get(message).subscribe(res =>
operateChanges(operMessage, OperationState.failure, message); operateChanges(operMessage, OperationState.failure, res)
return observableThrowError(message);
} else {
return this.translateService.get("BATCH.DELETED_FAILURE").pipe(
map(res => {
operateChanges(operMessage, OperationState.failure, res);
})
); );
} return observableThrowError(message);
})); }));
} }
} }

View File

@ -60,6 +60,7 @@ import {
} from "../operation/operate"; } from "../operation/operate";
import { OperationService } from "../operation/operation.service"; import { OperationService } from "../operation/operation.service";
import { Router } from "@angular/router"; import { Router } from "@angular/router";
import { errorHandler as errorHandFn } from "../shared/shared.utils";
const ONE_HOUR_SECONDS: number = 3600; const ONE_HOUR_SECONDS: number = 3600;
const ONE_MINUTE_SECONDS: number = 60; const ONE_MINUTE_SECONDS: number = 60;
const ONE_DAY_SECONDS: number = 24 * ONE_HOUR_SECONDS; const ONE_DAY_SECONDS: number = 24 * ONE_HOUR_SECONDS;
@ -327,23 +328,11 @@ export class ReplicationComponent implements OnInit, OnDestroy {
); );
}), }),
catchError(error => { catchError(error => {
if (error && error.status === 504) { const message = errorHandFn(error);
return this.translateService.get("BATCH.TIME_OUT").pipe( this.translateService.get(message).subscribe(res =>
map(res => { operateChanges(operMessage, OperationState.failure, res)
operateChanges(operMessage, OperationState.failure, res);
})
); );
} else if (error && error._body) {
const message = JSON.parse(error._body).message;
operateChanges(operMessage, OperationState.failure, message);
return observableThrowError(message); return observableThrowError(message);
} else {
return this.translateService.get("BATCH.REPLICATE_FAILURE").pipe(
map(res => {
operateChanges(operMessage, OperationState.failure, res);
})
);
}
}) })
); );
} }
@ -440,17 +429,11 @@ export class ReplicationComponent implements OnInit, OnDestroy {
); );
}), }),
catchError(error => { catchError(error => {
if (error && error._body) { const message = errorHandFn(error);
const message = JSON.parse(error._body).message; this.translateService.get(message).subscribe(res =>
operateChanges(operMessage, OperationState.failure, message); operateChanges(operMessage, OperationState.failure, res)
return observableThrowError(message);
} else {
return this.translateService.get("BATCH.STOP_FAILURE").pipe(
map(res => {
operateChanges(operMessage, OperationState.failure, res);
})
); );
} return observableThrowError(message);
}) })
); );
} }

View File

@ -41,6 +41,7 @@ import { OperateInfo, OperationState, operateChanges } from "../operation/operat
import { SERVICE_CONFIG, IServiceConfig } from '../service.config'; import { SERVICE_CONFIG, IServiceConfig } from '../service.config';
import { map, catchError } from "rxjs/operators"; import { map, catchError } from "rxjs/operators";
import { Observable, throwError as observableThrowError } from "rxjs"; import { Observable, throwError as observableThrowError } from "rxjs";
import { errorHandler as errorHandFn } from "../shared/shared.utils";
@Component({ @Component({
selector: "hbr-repository-gridview", selector: "hbr-repository-gridview",
templateUrl: "./repository-gridview.component.html", templateUrl: "./repository-gridview.component.html",
@ -212,21 +213,11 @@ export class RepositoryGridviewComponent implements OnChanges, OnInit {
operateChanges(operMessage, OperationState.success); operateChanges(operMessage, OperationState.success);
}); });
}), catchError(error => { }), catchError(error => {
if (error.status === "412") { const message = errorHandFn(error);
return forkJoin(this.translateService.get('BATCH.DELETED_FAILURE'), this.translateService.get(message).subscribe(res =>
this.translateService.get('REPOSITORY.TAGS_SIGNED')).pipe(map(res => { operateChanges(operMessage, OperationState.failure, res)
operateChanges(operMessage, OperationState.failure, res[1]); );
})); return observableThrowError(message);
}
if (error.status === 503) {
return forkJoin(this.translateService.get('BATCH.DELETED_FAILURE'),
this.translateService.get('REPOSITORY.TAGS_NO_DELETE')).pipe(map(res => {
operateChanges(operMessage, OperationState.failure, res[1]);
}));
}
return this.translateService.get('BATCH.DELETED_FAILURE').pipe(map(res => {
operateChanges(operMessage, OperationState.failure, res);
}));
})); }));
} }
} }

View File

@ -23,9 +23,11 @@ export const errorHandler = function (error: any): string {
if (!error) { if (!error) {
return "UNKNOWN_ERROR"; return "UNKNOWN_ERROR";
} }
try {
if (error && error._body) { return JSON.parse(error._body).message;
return error._body; } catch (err) { }
if (error._body && error._body.message) {
return error._body.message;
} }
if (!(error.statusCode || error.status)) { if (!(error.statusCode || error.status)) {
@ -52,7 +54,6 @@ export const errorHandler = function (error: any): string {
} }
} }
}; };
export const extractJson = (res: Response) => { export const extractJson = (res: Response) => {
if (res.text() === '') { if (res.text() === '') {
return []; return [];

View File

@ -59,6 +59,7 @@ import { operateChanges, OperateInfo, OperationState } from "../operation/operat
import { OperationService } from "../operation/operation.service"; import { OperationService } from "../operation/operation.service";
import { ImageNameInputComponent } from "../image-name-input/image-name-input.component"; import { ImageNameInputComponent } from "../image-name-input/image-name-input.component";
import { map, catchError } from "rxjs/operators"; import { map, catchError } from "rxjs/operators";
import { errorHandler as errorHandFn } from "../shared/shared.utils";
import { Observable, throwError as observableThrowError } from "rxjs"; import { Observable, throwError as observableThrowError } from "rxjs";
export interface LabelState { export interface LabelState {
iconsShow: boolean; iconsShow: boolean;
@ -668,15 +669,11 @@ export class TagComponent implements OnInit, AfterViewInit {
operateChanges(operMessage, OperationState.success); operateChanges(operMessage, OperationState.success);
}); });
}), catchError(error => { }), catchError(error => {
if (error.status === 503) { const message = errorHandFn(error);
return forkJoin(this.translateService.get('BATCH.DELETED_FAILURE'), this.translateService.get(message).subscribe(res =>
this.translateService.get('REPOSITORY.TAGS_NO_DELETE')).pipe(map(res => { operateChanges(operMessage, OperationState.failure, res)
operateChanges(operMessage, OperationState.failure, res[1]); );
})); return observableThrowError(message);
}
return this.translateService.get("BATCH.DELETED_FAILURE").pipe(map(res => {
operateChanges(operMessage, OperationState.failure, res);
}));
})); }));
} }
} }

View File

@ -17,7 +17,8 @@ import { AddGroupModalComponent } from "./add-group-modal/add-group-modal.compon
import { UserGroup } from "./group"; import { UserGroup } from "./group";
import { GroupService } from "./group.service"; import { GroupService } from "./group.service";
import { MessageHandlerService } from "../shared/message-handler/message-handler.service"; import { MessageHandlerService } from "../shared/message-handler/message-handler.service";
import { errorHandler as errorHandFn } from "../shared/shared.utils";
import { Observable, throwError as observableThrowError } from "rxjs";
@Component({ @Component({
selector: "app-group", selector: "app-group",
templateUrl: "./group.component.html", templateUrl: "./group.component.html",
@ -43,7 +44,8 @@ export class GroupComponent implements OnInit, OnDestroy {
private operateDialogService: ConfirmationDialogService, private operateDialogService: ConfirmationDialogService,
private groupService: GroupService, private groupService: GroupService,
private msgHandler: MessageHandlerService, private msgHandler: MessageHandlerService,
private session: SessionService private session: SessionService,
private translateService: TranslateService,
) { } ) { }
ngOnInit() { ngOnInit() {
@ -128,11 +130,12 @@ export class GroupComponent implements OnInit, OnDestroy {
return of(res); return of(res);
})); }));
})) }))
.pipe(catchError(err => { .pipe(catchError(error => {
return this.translate.get("BATCH.DELETED_FAILURE").pipe(flatMap(res => { const message = errorHandFn(error);
operateChanges(operMessage, OperationState.failure, res); this.translateService.get(message).subscribe(res =>
return of(res); operateChanges(operMessage, OperationState.failure, res)
})); );
return observableThrowError(message);
})); }));
}); });

View File

@ -8,8 +8,8 @@ import {
Output, Output,
EventEmitter EventEmitter
} from "@angular/core"; } from "@angular/core";
import { Observable, forkJoin } from "rxjs"; import { Observable, forkJoin, throwError as observableThrowError } from "rxjs";
import { finalize, map } from "rxjs/operators"; import { finalize, map, catchError } from "rxjs/operators";
import { TranslateService } from "@ngx-translate/core"; import { TranslateService } from "@ngx-translate/core";
import { State, import { State,
@ -41,6 +41,7 @@ import {
ResourceType, ResourceType,
Roles Roles
} from "../../../../shared/shared.const"; } from "../../../../shared/shared.const";
import { errorHandler as errorHandFn } from "../../../../shared/shared.utils";
@Component({ @Component({
selector: "hbr-helm-chart-version", selector: "hbr-helm-chart-version",
@ -95,6 +96,7 @@ export class ChartVersionComponent implements OnInit {
public userPermissionService: UserPermissionService, public userPermissionService: UserPermissionService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private operationService: OperationService, private operationService: OperationService,
private translateService: TranslateService,
) { } ) { }
public get registryUrl(): string { public get registryUrl(): string {
@ -175,8 +177,14 @@ export class ChartVersionComponent implements OnInit {
.deleteChartVersion(this.projectName, this.chartName, version.version) .deleteChartVersion(this.projectName, this.chartName, version.version)
.pipe(map( .pipe(map(
() => operateChanges(operateMsg, OperationState.success), () => operateChanges(operateMsg, OperationState.success),
err => operateChanges(operateMsg, OperationState.failure, err) catchError( error => {
)); const message = errorHandFn(error);
this.translateService.get(message).subscribe(res =>
operateChanges(operateMsg, OperationState.failure, res)
);
return observableThrowError(message);
}
)));
} }
deleteVersions(versions: HelmChartVersion[]) { deleteVersions(versions: HelmChartVersion[]) {

View File

@ -14,7 +14,7 @@ import {
State, ErrorHandler, SystemInfo, SystemInfoService, DEFAULT_PAGE_SIZE, downloadFile State, ErrorHandler, SystemInfo, SystemInfoService, DEFAULT_PAGE_SIZE, downloadFile
, OperationService, UserPermissionService, USERSTATICPERMISSION, OperateInfo, OperationState, operateChanges , OperationService, UserPermissionService, USERSTATICPERMISSION, OperateInfo, OperationState, operateChanges
} from "@harbor/ui"; } from "@harbor/ui";
import { forkJoin, throwError, Observable } from "rxjs"; import { forkJoin, throwError as observableThrowError, Observable } from "rxjs";
import { finalize, map, catchError } from "rxjs/operators"; import { finalize, map, catchError } from "rxjs/operators";
import { HelmChartItem } from "../helm-chart.interface.service"; import { HelmChartItem } from "../helm-chart.interface.service";
import { HelmChartService } from "../helm-chart.service"; import { HelmChartService } from "../helm-chart.service";
@ -28,6 +28,7 @@ import {
ConfirmationTargets, ConfirmationTargets,
ConfirmationState, ConfirmationState,
} from "../../../shared/shared.const"; } from "../../../shared/shared.const";
import { errorHandler as errorHandFn } from "../../../shared/shared.utils";
@Component({ @Component({
selector: "hbr-helm-chart", selector: "hbr-helm-chart",
@ -202,8 +203,14 @@ export class HelmChartComponent implements OnInit {
return this.helmChartService.deleteHelmChart(this.projectName, chartName) return this.helmChartService.deleteHelmChart(this.projectName, chartName)
.pipe(map( .pipe(map(
() => operateChanges(operateMsg, OperationState.success), () => operateChanges(operateMsg, OperationState.success),
err => operateChanges(operateMsg, OperationState.failure, err) catchError( error => {
)); const message = errorHandFn(error);
this.translateService.get(message).subscribe(res =>
operateChanges(operateMsg, OperationState.failure, res)
);
return observableThrowError(message);
}
)));
} }
deleteCharts(charts: HelmChartItem[]) { deleteCharts(charts: HelmChartItem[]) {
@ -211,7 +218,7 @@ export class HelmChartComponent implements OnInit {
let chartsDelete$ = charts.map(chart => this.deleteChart(chart.name)); let chartsDelete$ = charts.map(chart => this.deleteChart(chart.name));
forkJoin(chartsDelete$) forkJoin(chartsDelete$)
.pipe( .pipe(
catchError(err => throwError(err)), catchError(err => observableThrowError(err)),
finalize(() => { finalize(() => {
this.refresh(); this.refresh();
this.selectedRows = []; this.selectedRows = [];

View File

@ -41,6 +41,8 @@ import { Project } from "../project";
import { ProjectService } from "../project.service"; import { ProjectService } from "../project.service";
import { map, catchError } from "rxjs/operators"; import { map, catchError } from "rxjs/operators";
import { throwError as observableThrowError } from "rxjs"; import { throwError as observableThrowError } from "rxjs";
import { errorHandler as errorHandFn } from "../../shared/shared.utils";
@Component({ @Component({
selector: "list-project", selector: "list-project",
templateUrl: "list-project.component.html", templateUrl: "list-project.component.html",
@ -78,6 +80,7 @@ export class ListProjectComponent implements OnDestroy {
private translate: TranslateService, private translate: TranslateService,
private deletionDialogService: ConfirmationDialogService, private deletionDialogService: ConfirmationDialogService,
private operationService: OperationService, private operationService: OperationService,
private translateService: TranslateService,
private ref: ChangeDetectorRef) { private ref: ChangeDetectorRef) {
this.subscription = deletionDialogService.confirmationConfirm$.subscribe(message => { this.subscription = deletionDialogService.confirmationConfirm$.subscribe(message => {
if (message && if (message &&
@ -274,16 +277,11 @@ export class ListProjectComponent implements OnDestroy {
}); });
}), catchError( }), catchError(
error => { error => {
if (error && error.status === 412) { const message = errorHandFn(error);
return observableForkJoin(this.translate.get("BATCH.DELETED_FAILURE"), this.translateService.get(message).subscribe(res =>
this.translate.get("PROJECT.FAILED_TO_DELETE_PROJECT")).pipe(map(res => { operateChanges(operMessage, OperationState.failure, res)
operateChanges(operMessage, OperationState.failure, res[1]); );
})); return observableThrowError(message);
} else {
return this.translate.get("BATCH.DELETED_FAILURE").pipe(map(res => {
operateChanges(operMessage, OperationState.failure, res);
}));
}
})); }));
} }

View File

@ -15,7 +15,8 @@ import { GroupService } from "../../../group/group.service";
import { ProjectRoles } from "../../../shared/shared.const"; import { ProjectRoles } from "../../../shared/shared.const";
import { MessageHandlerService } from '../../../shared/message-handler/message-handler.service'; import { MessageHandlerService } from '../../../shared/message-handler/message-handler.service';
import { Member } from "../member"; import { Member } from "../member";
import { throwError as observableThrowError } from "rxjs";
import { errorHandler as errorHandFn } from "../../../shared/shared.utils";
@Component({ @Component({
selector: "add-group", selector: "add-group",
templateUrl: "./add-group.component.html", templateUrl: "./add-group.component.html",
@ -135,12 +136,14 @@ export class AddGroupComponent implements OnInit {
operateChanges(operMessage, OperationState.success); operateChanges(operMessage, OperationState.success);
return observableOf(res); return observableOf(res);
})); }), })); }),
catchError(error => { catchError(
return this.translateService.get("BATCH.DELETED_FAILURE").pipe( error => {
mergeMap(res => { const message = errorHandFn(error);
operateChanges(operMessage, OperationState.failure, res); this.translateService.get(message).subscribe(res =>
return observableOf(res); operateChanges(operMessage, OperationState.failure, res)
})); }), );
return observableThrowError(message);
}),
catchError(error => observableOf(error.status)), ); catchError(error => observableOf(error.status)), );
}); });
forkJoin(GroupAdders$) forkJoin(GroupAdders$)

View File

@ -34,6 +34,7 @@ import { AddMemberComponent } from "./add-member/add-member.component";
import { AppConfigService } from "../../app-config.service"; import { AppConfigService } from "../../app-config.service";
import { UserPermissionService, USERSTATICPERMISSION, ErrorHandler } from "@harbor/ui"; import { UserPermissionService, USERSTATICPERMISSION, ErrorHandler } from "@harbor/ui";
import { map, catchError } from "rxjs/operators"; import { map, catchError } from "rxjs/operators";
import { errorHandler as errorHandFn } from "../../shared/shared.utils";
import { throwError as observableThrowError } from "rxjs"; import { throwError as observableThrowError } from "rxjs";
@Component({ @Component({
templateUrl: "member.component.html", templateUrl: "member.component.html",
@ -260,9 +261,11 @@ export class MemberComponent implements OnInit, OnDestroy {
operateChanges(operMessage, OperationState.success); operateChanges(operMessage, OperationState.success);
}); });
}), catchError(error => { }), catchError(error => {
return this.translate.get("BATCH.DELETED_FAILURE").pipe(map(res => { const message = errorHandFn(error);
operateChanges(operMessage, OperationState.failure, res); this.translate.get(message).subscribe(res =>
})); operateChanges(operMessage, OperationState.failure, res)
);
return observableThrowError(message);
})); }));
}; };

View File

@ -11,7 +11,7 @@ import { Robot } from "./robot";
import { Project } from "./../project"; import { Project } from "./../project";
import { finalize, catchError, map } from "rxjs/operators"; import { finalize, catchError, map } from "rxjs/operators";
import { TranslateService } from "@ngx-translate/core"; import { TranslateService } from "@ngx-translate/core";
import { Subscription, forkJoin, Observable, throwError } from "rxjs"; import { Subscription, forkJoin, Observable, throwError as observableThrowError } from "rxjs";
import { MessageHandlerService } from "../../shared/message-handler/message-handler.service"; import { MessageHandlerService } from "../../shared/message-handler/message-handler.service";
import { RobotService } from "./robot-account.service"; import { RobotService } from "./robot-account.service";
import { ConfirmationMessage } from "../../shared/confirmation-dialog/confirmation-message"; import { ConfirmationMessage } from "../../shared/confirmation-dialog/confirmation-message";
@ -30,7 +30,7 @@ import {
USERSTATICPERMISSION, USERSTATICPERMISSION,
ErrorHandler ErrorHandler
} from "@harbor/ui"; } from "@harbor/ui";
import { errorHandler as errorHandFn } from "../../shared/shared.utils";
@Component({ @Component({
selector: "app-robot-account", selector: "app-robot-account",
templateUrl: "./robot-account.component.html", templateUrl: "./robot-account.component.html",
@ -140,7 +140,7 @@ export class RobotAccountComponent implements OnInit, OnDestroy {
let robotsDelete$ = robots.map(robot => this.delOperate(robot)); let robotsDelete$ = robots.map(robot => this.delOperate(robot));
forkJoin(robotsDelete$) forkJoin(robotsDelete$)
.pipe( .pipe(
catchError(err => throwError(err)), catchError(err => observableThrowError(err)),
finalize(() => { finalize(() => {
this.retrieve(); this.retrieve();
this.selectedRow = []; this.selectedRow = [];
@ -163,9 +163,15 @@ export class RobotAccountComponent implements OnInit, OnDestroy {
.pipe( .pipe(
map( map(
() => operateChanges(operMessage, OperationState.success), () => operateChanges(operMessage, OperationState.success),
err => operateChanges(operMessage, OperationState.failure, err) catchError(error => {
) const errorMsg = errorHandFn(error);
this.translate.get(errorMsg).subscribe(res =>
operateChanges(operMessage, OperationState.failure, res)
); );
return observableThrowError(errorMsg);
}
)
));
} }
createAccount(created: boolean): void { createAccount(created: boolean): void {

View File

@ -26,16 +26,21 @@ import { httpStatusCode, AlertType } from './shared.const';
* returns {string} * returns {string}
*/ */
export const errorHandler = function (error: any): string { export const errorHandler = function (error: any): string {
if (typeof error === "string") { if (!error) {
return error; return "UNKNOWN_ERROR";
} }
if (error && error._body) {
try {
return JSON.parse(error._body).message;
} catch (err) { }
if (error._body && error._body.message) {
return error._body.message;
}
if (!(error.statusCode || error.status)) {
// treat as string message // treat as string message
if (typeof error._body === "string") { return '' + error;
return error._body;
} else if (error._body.error) {
return error._body.error;
}
} else { } else {
switch (error.statusCode || error.status) { switch (error.statusCode || error.status) {
case 400: case 400:

View File

@ -30,6 +30,7 @@ import { ChangePasswordComponent } from "./change-password/change-password.compo
import { operateChanges, OperateInfo, OperationService, OperationState } from "@harbor/ui"; import { operateChanges, OperateInfo, OperationService, OperationState } from "@harbor/ui";
import { map, catchError } from 'rxjs/operators'; import { map, catchError } from 'rxjs/operators';
import { throwError as observableThrowError } from "rxjs"; import { throwError as observableThrowError } from "rxjs";
import { errorHandler as errorHandFn } from "../shared/shared.utils";
/** /**
* NOTES: * NOTES:
@ -296,9 +297,11 @@ export class UserComponent implements OnInit, OnDestroy {
operateChanges(operMessage, OperationState.success); operateChanges(operMessage, OperationState.success);
}); });
}, catchError(error => { }, catchError(error => {
return this.translate.get('BATCH.DELETED_FAILURE').pipe(map(res => { const message = errorHandFn(error);
operateChanges(operMessage, OperationState.failure, res); this.translate.get(message).subscribe(res =>
})); operateChanges(operMessage, OperationState.failure, res)
);
return observableThrowError(message);
}))); })));
} }