Issue
I am calling an http request using httpClient and using response Type as 'blob' but the problem is when it goes in error block the response type remains 'blob'.This is causing problem with my error handling.
this.httpClient.get('http://m502126:3000/reports/perdate', {
observe: 'body',
responseType: 'blob',
params: new HttpParams().set('START_DATE', startDate)
.set('END_DATE', endDate)
.set('MIXER', mixer)
.set('ATTACH', 'true')
}).subscribe(data => {
console.log(data);
},
error => {
console.log(error);
}
)
the problem is i am setting request type as'blob' and type of error is any . So when error comes and goes in error block the response type remains 'blob'. How to handle this ?
Solution
It can also be done with: error.text()
this.dataService
.getFile()
.subscribe((response) => {
FileSaver.saveAs(response.body, 'file.txt');
}, async (error) => {
const message = JSON.parse(await error.error.text()).message;
this.toast.error(message, 'Error');
});
Answered By - Marian
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.