error is undefinied from OnError($event)

- [ ] Regression (a behavior that used to work and stopped working in a new release)
- [x] Bug report -> please search issues before submitting
- [ ] Feature request
- [ ] Documentation issue or request

Hello, I don’t know if this behavior is normal but I’m having trouble getting details of an (intentional) error
here is my PDF viewer in HTML

<pdf-viewer 
  [src]="PDF" 
  [render-text]="true"
  style="display: block;"
  (on-progress)="onProgress($event)"
  (after-load-complete)='PDF_loaded()'
  (error)="onError($event)">
</pdf-viewer>

and here is the onError function in the .TS

onError(errorPDF: any){console.log(errorPDF)}

the url of the pdf request returns a 404 error (as intended in my EXPRESS api )

res.status(404).send({ error: 'Not Found' });

In the chrome console i only get an ‘undefined’ for the ‘console.log (error PDF)’
Is it normal? Is there a way to get the code error thanks to the ‘OnError’ function?

Thanks

1 possible answer(s) on “error is undefinied from OnError($event)

  1. Found it. The error message is a victim of minification. If you’re using the non-minified version of the pdf.worker.js, the error object has a sensible value. In my case, I’ve added this line to the app.module.ts:

    (window as any).pdfWorkerSrc = 'https://cdn.jsdelivr.net/npm/pdfjs-dist@2.5.207/build/pdf.worker.js';