Skip to content
Snippets Groups Projects
Commit 7db09737 authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Improve error handling on download button

parent 9ca9bfab
No related branches found
No related tags found
1 merge request!73Development
Pipeline #5081 passed
...@@ -262,13 +262,19 @@ export class ResourceDownloadItemComponent implements OnInit { ...@@ -262,13 +262,19 @@ export class ResourceDownloadItemComponent implements OnInit {
transformObjectToArray(object) { transformObjectToArray(object) {
const array = []; const array = [];
const keys = Object.keys(object); let keys;
keys.forEach((key) => {
array.push({ if (object) {
name: key, keys = Object.keys(object);
bbox: object[key],
keys.forEach((key) => {
array.push({
name: key,
bbox: object[key],
});
}); });
}); }
return array; return array;
} }
......
...@@ -27,7 +27,7 @@ export class DownloadButtonComponent implements OnInit, OnDestroy { ...@@ -27,7 +27,7 @@ export class DownloadButtonComponent implements OnInit, OnDestroy {
private _http: HttpClient, private _http: HttpClient,
) { } ) { }
ngOnInit() {} ngOnInit() { }
download() { download() {
this.loading = true; this.loading = true;
...@@ -35,7 +35,6 @@ export class DownloadButtonComponent implements OnInit, OnDestroy { ...@@ -35,7 +35,6 @@ export class DownloadButtonComponent implements OnInit, OnDestroy {
takeUntil(this.ngUnsubscribe), takeUntil(this.ngUnsubscribe),
).subscribe( ).subscribe(
(response) => { (response) => {
console.log('Reponse');
// Create a temporary link and click on it to launch the blob download // Create a temporary link and click on it to launch the blob download
const url = window.URL.createObjectURL(response.body); const url = window.URL.createObjectURL(response.body);
const a = document.createElement('a'); const a = document.createElement('a');
...@@ -50,23 +49,23 @@ export class DownloadButtonComponent implements OnInit, OnDestroy { ...@@ -50,23 +49,23 @@ export class DownloadButtonComponent implements OnInit, OnDestroy {
(err) => { (err) => {
let message = notificationMessages.general.failedDownloadFile; let message = notificationMessages.general.failedDownloadFile;
if (err && err.status) { if (err && err.status === 401) {
switch (err.status) {
case 401: message = notificationMessages.general.failedDownloadFileUnauthenticated;
message = notificationMessages.general.failedDownloadFileUnauthenticated; }
break;
case 403: if (err && err.status === 403) {
message = notificationMessages.general.failedDownloadFileUnauthorized; message = notificationMessages.general.failedDownloadFileUnauthorized;
break;
}
this.abortDownload();
this._notificationService.notify(
{
message,
type: 'error',
},
);
} }
this._notificationService.notify(
{
message,
type: 'error',
},
);
this.abortDownload();
}, },
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment