Skip to content

Commit

Permalink
KYLO-3186: fix feed export error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
harschware committed Dec 10, 2018
1 parent f0b3ed5 commit eb4271c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
}
Expand All @@ -67,7 +65,7 @@ export class FeedOperationsHealthInfoComponent implements OnInit, OnDestroy {

exportFeedUrl: string;

exportInProgress:boolean= false;
exportInProgress: boolean = false;

restUrlService: RestUrlService;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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:")) {
Expand Down

0 comments on commit eb4271c

Please sign in to comment.