Skip to content

Commit

Permalink
Merge pull request #257 from aranaravi/develop
Browse files Browse the repository at this point in the history
[MOSIP-23353] Handling error upon clicked download button
  • Loading branch information
aranaravi authored Jan 4, 2024
2 parents 10c7ab0 + 8be9571 commit 73f776c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions admin-ui/src/app/core/services/httpinterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export class AuthInterceptor implements HttpInterceptor {
});
} else {
if (err.url.includes('validateToken')) {

this.translateService
.getTranslation(this.appService.getConfig().primaryLangCode)
.subscribe(response => {
Expand All @@ -142,7 +141,8 @@ export class AuthInterceptor implements HttpInterceptor {
disableClose: true
});
});

}else if(err.url.includes('rid-digital-card')) {
console.log("download card");
}else{
this.translateService
.getTranslation(this.appService.getConfig().primaryLangCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DialogComponent } from 'src/app/shared/dialog/dialog.component';
import { DomSanitizer } from '@angular/platform-browser';
import { saveAs } from 'file-saver';
import { ActivatedRoute, Router, NavigationEnd } from '@angular/router';
import { HttpErrorResponse } from '@angular/common/http';

@Component({
selector: 'app-download-card',
Expand Down Expand Up @@ -123,7 +124,8 @@ export class DownloadCardComponent implements OnInit {
if(selection === 'true'){
this.auditService.audit(21, 'ADM-045', {'type':'download-card','actioned':'Verify and Download'});
this.dataStorageService
.downloadCard(this.id).subscribe(data => {
.downloadCard(this.id).subscribe(
(data) => {
var fileName = this.id+".pdf";
const contentDisposition = data.headers.get('Content-Disposition');
if (contentDisposition) {
Expand All @@ -135,15 +137,25 @@ export class DownloadCardComponent implements OnInit {
}
saveAs(data.body, fileName);
},
err => {
console.error(err);
(error: HttpErrorResponse) => {
const errorJson = JSON.parse(this.blobToString(error.error));
this.showErrorPopup(errorJson.errors[0].message);
});
}else{
this.auditService.audit(21, 'ADM-045', {'type':'download-card','actioned':'Reject'});
location.reload();
}
}

private blobToString(blob): string {
const url = URL.createObjectURL(blob);
let xmlRequest = new XMLHttpRequest();
xmlRequest.open('GET', url, false);
xmlRequest.send();
URL.revokeObjectURL(url);
return xmlRequest.responseText;
}

viewMore() {
this.showTimeline = !this.showTimeline;
}
Expand Down

0 comments on commit 73f776c

Please sign in to comment.