Commit 7db09737 authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Improve error handling on download button

parent 9ca9bfab
Pipeline #5081 passed with stage
in 3 minutes and 26 seconds
......@@ -262,13 +262,19 @@ export class ResourceDownloadItemComponent implements OnInit {
transformObjectToArray(object) {
const array = [];
const keys = Object.keys(object);
keys.forEach((key) => {
array.push({
name: key,
bbox: object[key],
let keys;
if (object) {
keys = Object.keys(object);
keys.forEach((key) => {
array.push({
name: key,
bbox: object[key],
});
});
});
}
return array;
}
......
......@@ -27,7 +27,7 @@ export class DownloadButtonComponent implements OnInit, OnDestroy {
private _http: HttpClient,
) { }
ngOnInit() {}
ngOnInit() { }
download() {
this.loading = true;
......@@ -35,7 +35,6 @@ export class DownloadButtonComponent implements OnInit, OnDestroy {
takeUntil(this.ngUnsubscribe),
).subscribe(
(response) => {
console.log('Reponse');
// Create a temporary link and click on it to launch the blob download
const url = window.URL.createObjectURL(response.body);
const a = document.createElement('a');
......@@ -50,23 +49,23 @@ export class DownloadButtonComponent implements OnInit, OnDestroy {
(err) => {
let message = notificationMessages.general.failedDownloadFile;
if (err && err.status) {
switch (err.status) {
case 401:
message = notificationMessages.general.failedDownloadFileUnauthenticated;
break;
case 403:
message = notificationMessages.general.failedDownloadFileUnauthorized;
break;
}
this.abortDownload();
this._notificationService.notify(
{
message,
type: 'error',
},
);
if (err && err.status === 401) {
message = notificationMessages.general.failedDownloadFileUnauthenticated;
}
if (err && err.status === 403) {
message = notificationMessages.general.failedDownloadFileUnauthorized;
}
this._notificationService.notify(
{
message,
type: 'error',
},
);
this.abortDownload();
},
);
}
......
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