1

I'm handing errors in my Angular app using RxJS like this:

  public downloadInClient(fileName: string) {
    return (source: Observable<Blob>) =>
      source.pipe(
        map((blob: Blob) => {
          this.downloadPDF(blob, fileName);
          return blob;
        }),
        catchError((error: any) => {
          console.error(error);
          this.handleError(error);
          return EMPTY;
        }),
      );
  }

Any idea why in local I can see the object error with its fields when an error is caught, but after building and deploying the app, the error is caught in the correct place but when console.error it, is shows itself as undefined?

I have tried to frame all inside a try catch, but because the error is caught before, inside the catchError, the code doesn't arrive to the outside catch.

1
  • please share the minimal reproducible code, how are you using downloadInClient Commented May 6 at 14:04

1 Answer 1

0

Might be you are not giving the source correctly. If you have a fileName in your function then there should be server call to get the content from backend. May be below code in your main function will help you.

return this.http.get(url+fileName, {
  responseType: 'blob',
  headers: new HttpHeaders().append('Content-Type', 'application/pdf'),
  params: new HttpParams()
}).pipe(
  map((source: Blob) => {
    // to download the file
    const blob = new Blob([source], { type: 'application/pdf' });
    const downloadLink = document.createElement('a');
    downloadLink.href = URL.createObjectURL(blob);
    downloadLink.download = fileName;
    downloadLink.click();
    URL.revokeObjectURL(downloadLink.href);
    return source;
  }),
  catchError((error: any) => {
    console.error(error);
    this.handleError(error);
    return EMPTY;
  }),
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.