发出带有responseType:'arraybuffer'

时间:2018-12-26 13:49:43

标签: angular typescript

我已经使用HttpClient发出服务器请求以下载资源。.当服务器上找不到资源时,我的Spring Boot应用程序将引发错误““证书尚未打印”。.我可以从服务器下载文件但是当服务器抛出500错误时,我得到了空错误对象。

我注释掉后得到预期的结果-responseType:'arraybuffer',但是我无法下载文件...

downloadFile(fileName): Observable<any> {
  console.log("--------factory-safety-form.service.ts----------downloadFile()-------");
  //let body = {f_formId: -1};
  let body = {fileName: fileName};
  const headers = new HttpHeaders().set('Content-Type', 'text/plain; charset=utf-8');
  return this.http.post(AppSettings.API_ENDPOINT + '/fsform/download', body,{
    responseType: 'arraybuffer',
    headers: headers
  }); 

实际结果:

"{
    "headers":{
       "normalizedNames":{},
       "lazyUpdate":null,
       "lazyInit":null,
       "headers":{}
    },
    "status":500,
    "statusText":"OK",
    "url":"http://localhost:8080/fsform/download",
    "ok":false,
    "name":"HttpErrorResponse",
    "message":"Http failure response for http://localhost:8080/fsform/download: 500 OK",
    "error":{}
}"

预期结果:

{
    "headers":{
         "normalizedNames":{},
         "lazyUpdate":null,
         "lazyInit":null,
         "headers":{}
    },
    "status":500,
    "statusText":"OK",
    "url":"http://localhost:8080/fsform/download",
    "ok":false,
    "name":"HttpErrorResponse",
    "message":"Http failure response for http://localhost:8080/fsform/download: 500 OK",
    "error":{
         "timestamp":"2018-12-26T19:14:01.398+0530",
         "status":500,"error":"Internal Server Error",
         "message":"Certificates Not Printed Yet",
         "path":"/fsform/download"
     }
 }

0 个答案:

没有答案