From eb4271ca8ef979ec4ea8a635fee5464b8f83de10 Mon Sep 17 00:00:00 2001 From: Tim Harsch Date: Mon, 10 Dec 2018 08:42:04 -0800 Subject: [PATCH] KYLO-3186: fix feed export error messages --- .../feed-operations-health-info.component.ts | 60 ++++++++++--------- .../js/services/AngularHttpInterceptor.ts | 20 ++++++- 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/ui/ui-app/src/main/resources/static/js/feed-mgr/feeds/define-feed-ng2/summary/feed-activity-summary/feed-operations-health-info/feed-operations-health-info.component.ts b/ui/ui-app/src/main/resources/static/js/feed-mgr/feeds/define-feed-ng2/summary/feed-activity-summary/feed-operations-health-info/feed-operations-health-info.component.ts index 6600b9fb39..dab22b2b2b 100644 --- a/ui/ui-app/src/main/resources/static/js/feed-mgr/feeds/define-feed-ng2/summary/feed-activity-summary/feed-operations-health-info/feed-operations-health-info.component.ts +++ b/ui/ui-app/src/main/resources/static/js/feed-mgr/feeds/define-feed-ng2/summary/feed-activity-summary/feed-operations-health-info/feed-operations-health-info.component.ts @@ -7,14 +7,12 @@ import {OpsManagerFeedService} from "../../../../../../ops-mgr/services/ops-mana import {BroadcastService} from "../../../../../../services/broadcast-service"; import {FeedStats} from "../../../../../model/feed/feed-stats.model"; import {FeedSummary} from "../../../../../model/feed/feed-summary.model"; -import {Feed, FeedAccessControl} from "../../../../../model/feed/feed.model"; +import {Feed} from "../../../../../model/feed/feed.model"; import {DefineFeedService} from "../../../services/define-feed.service"; import {FeedUploadFileDialogComponent, FeedUploadFileDialogComponentData} from "../feed-upload-file-dialog/feed-upload-file-dialog.component"; import {RestUrlService} from "../../../../../services/RestUrlService"; import {HttpClient} from "@angular/common/http"; import {Observable} from "rxjs/Observable"; -import {RequestOptions, ResponseContentType} from "@angular/http"; -import {NotificationService} from "../../../../../../services/notification.service"; import {MatSnackBar} from "@angular/material/snack-bar"; import {FeedOperationsSummary} from "../../../../../model/feed/feed-operations-summary.model"; @@ -47,12 +45,12 @@ export class FeedOperationsHealthInfoComponent implements OnInit, OnDestroy { refreshTime: number = 10000; - constructor(private http:HttpClient,private opsManagerFeedService: OpsManagerFeedService, + constructor(private http: HttpClient, private opsManagerFeedService: OpsManagerFeedService, @Inject("BroadcastService") private broadcastService: BroadcastService, private _dialogService: TdDialogService, private defineFeedService: DefineFeedService, @Inject("RestUrlService") restUrlService: RestUrlService, - private snackBar:MatSnackBar) { + private snackBar: MatSnackBar) { this.broadcastService.subscribe(null, 'ABANDONED_ALL_JOBS', this.getFeedHealth.bind(this)); this.restUrlService = restUrlService; } @@ -67,7 +65,7 @@ export class FeedOperationsHealthInfoComponent implements OnInit, OnDestroy { exportFeedUrl: string; - exportInProgress:boolean= false; + exportInProgress: boolean = false; restUrlService: RestUrlService; @@ -108,43 +106,51 @@ export class FeedOperationsHealthInfoComponent implements OnInit, OnDestroy { } } + uintToString(uintArray) { + return String.fromCharCode.apply(null, new Uint8Array(uintArray)); + } + + exportFeed() { - //todo start progress + var snackBarRef = this.snackBar.open("Feed export is processing. Notification will appear when complete.", null, { + duration: 3000, + }); + this.exportInProgress = true; - this.snackBar.open("Feed export is processing. Notification will appear when complete.", null, { - duration: 3000, - }); - this.http.get(this.exportFeedUrl, {responseType:"arraybuffer"}) - .catch(errorResponse => { + this.http.get(this.exportFeedUrl, {observe: "response", responseType: "arraybuffer"}) + .catch((errorResponse) => { this.exportInProgress = false; + snackBarRef.dismiss(); return Observable.throw(errorResponse) - } ) + }) .map((response) => { return response; - }).subscribe(data => this.getZipFile(data)), - error => this._dialogService.openAlert({title:"Export Feed Error", message:"There was an error exporting the feed"}) - - + }) + .subscribe( + data => { + this.getZipFile(data); + this.exportInProgress = false; + this.snackBar.open("Feed export complete", null, { + duration: 3000, + }); + } + ) } - getZipFile(data: any){ + + getZipFile(data: any) { var a: any = document.createElement("a"); document.body.appendChild(a); a.style = "display: none"; - var blob = new Blob([data], { type: 'application/zip' }); + var blob = new Blob([data], {type: 'application/zip'}); - var url= window.URL.createObjectURL(blob); + var url = window.URL.createObjectURL(blob); a.href = url; - a.download = this.feed.systemFeedName+".feed.zip"; + a.download = this.feed.systemFeedName + ".feed.zip"; a.click(); window.URL.revokeObjectURL(url); - this.exportInProgress = false; - this.snackBar.open("Feed export complete", null, { - duration: 3000, - }); - } initMenu() { @@ -198,7 +204,7 @@ export class FeedOperationsHealthInfoComponent implements OnInit, OnDestroy { let error = (msg?: string) => { let message = msg ? msg : "The feed could not be started."; - let alertTitle = msg? "Started the feed" : "Error starting the feed"; + let alertTitle = msg ? "Started the feed" : "Error starting the feed"; this._dialogService.openAlert({ title: alertTitle, diff --git a/ui/ui-app/src/main/resources/static/js/services/AngularHttpInterceptor.ts b/ui/ui-app/src/main/resources/static/js/services/AngularHttpInterceptor.ts index 01f68b99b0..fe0076ca8c 100644 --- a/ui/ui-app/src/main/resources/static/js/services/AngularHttpInterceptor.ts +++ b/ui/ui-app/src/main/resources/static/js/services/AngularHttpInterceptor.ts @@ -78,6 +78,16 @@ export class AngularHttpInterceptor implements angular.IHttpInterceptor, HttpInt } } + + uintToString(uintArray) { + /* var encodedString = String.fromCharCode.apply(null, uintArray), + decodedString = decodeURIComponent(encodedString); + return decodedString; + */ + return String.fromCharCode.apply(null, new Uint8Array(uintArray)); + } + + /** * Handle error responses and redirect to login page if necessary. */ @@ -122,7 +132,15 @@ export class AngularHttpInterceptor implements angular.IHttpInterceptor, HttpInt } else if (data['handledException'] == undefined || (data['handledException'] != undefined && data['handledException'] == false)) { let message = "An error occurred "; let detailedMessage = data['message'] ? data['message'] : (Array.isArray(data['errorMessages']) ? data['errorMessages'][0] : null); - let rejectionMessage = data['message']; + + var rejectionMessage = data['message']; + if (rejection.error && rejection.error.constructor == ArrayBuffer ) { + var str = this.uintToString(rejection.error); + var json = JSON.parse(str); + console.log(json); + message += json.message; + } + if (rejectionMessage == undefined || rejectionMessage == '') { rejectionMessage = 'OtherError'; } else if (rejectionMessage.startsWith("AnalysisException:")) {