How to handle error for response Type blob in HttpRequest

后端 未结 5 2007

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 c

5条回答
  •  不思量自难忘°
    2021-01-07 23:49

    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');
      });
    

提交回复
热议问题