# How to properly handle errors

**URL:** <https://pdfjs.community/t/how-to-properly-handle-errors/1208>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [November 30, 2021, 4:46pm UTC](https://pdfjs.community/t/how-to-properly-handle-errors/1208 "2021-11-30T16:46:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user13](https://avatars.discourse-cdn.com/v4/letter/u/a88e57/32.png) [@user13](https://pdfjs.community/u/user13)\
**Post date:** [November 30, 2021, 4:46pm UTC](https://pdfjs.community/t/how-to-properly-handle-errors/1208/1 "2021-11-30T16:46:03Z")

</div>

Hi,

The documentation is not clear about how to handle errors. Although there is this here [PDF.js Express Viewer Events | Documentation (pdfjs.express)](https://pdfjs.express/documentation/learn-more/events.8#document-load-error-handling), this call is never triggered as per my tests.

Example:

- Setup the WebViewer as per the docs above
- Subscribe to the loaderror event
- Pass in a wrong url to the parameter `initialDoc`. This returns a 404 error in the network

The loaderror callback is never called.

I also tried adding a .catch() function to the Promise, but that was not called back either.

Can someone pls provide some guidance about how to handle errors? Here what I have tried:

```javascript
documentViewer.addEventListener('loaderror', () => {
          debugger // never get called
        })

```

And also this

```javascript
WebViewer({
        path: this.path,
        initialDoc: this.url,
        licenseKey: process.env.VUE_APP_PDFJS_KEY
      }, pdfViewer).then((instance) => {
        ...
        });
      }).catch(() => {
        debugger // never gets called 
      })

```

Thx

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/1X/ffbcd25c7d423db8d5acd5db201c272f4db306dd.png) [@system](https://pdfjs.community/u/system)\
**Post date:** [November 30, 2021, 4:46pm UTC](https://pdfjs.community/t/how-to-properly-handle-errors/1208/3 "2021-11-30T16:46:08Z")

</div>

**Hello, I’m Ron, an automated tech support bot 🤖**

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:
- [Integrating React with PDF.js Express Viewer JavaScript PDF library - 3. Place WebViewer into a component](https://pdfjs.express/documentation/get-started-viewer/react#3.-place-webviewer-into-a-component)
- [Events for PDF.js Express - Document Load Error Handling](https://pdfjs.express/documentation/learn-more/events.8#document-load-error-handling)
- [Integrating PDF.js Express Plus with React - 3. Place WebViewer into a component](https://pdfjs.express/documentation/get-started/react#3.-place-webviewer-into-a-component)

APIs:
- [UndefinedgetInstance( [element])](https://pdfjs.express/api/global.html#getInstance__anchor)
- [UI.VerificationOptions](https://pdfjs.express/api/UI.VerificationOptions.html#__anchor)
- [WebViewerInstance - new WebViewerInstance()](https://pdfjs.express/api/WebViewerInstance.html#WebViewerInstance__anchor)

Forums:
- [Using instance.loadDocument() inside useEffect to open a file](https://pdfjs.community/t/using-instance-loaddocument-inside-useeffect-to-open-a-file/318/1)
- [Webviewer initialization error](https://pdfjs.community/t/webviewer-initialization-error/173/1)
- [How to load different pdf on pdfjs express viewer on passing url through button click](https://pdfjs.community/t/how-to-load-different-pdf-on-pdfjs-express-viewer-on-passing-url-through-button-click/320/2)

---

<div class="post-metadata">

**Author:** ![Logan](https://yyz1.discourse-cdn.com/flex031/user_avatar/pdfjs.community/logan/32/13_2.png) [@Logan](https://pdfjs.community/u/Logan)\
**Post date:** [December 6, 2021, 10:25pm UTC](https://pdfjs.community/t/how-to-properly-handle-errors/1208/4 "2021-12-06T22:25:26Z")

</div>

Hey!

You can use this event:

```javascript
  instance.UI.addEventListener('loaderror', () => {
    console.log('error')
  })

```

(I realize this is not the best name or location for this event - I’ll talk to the team to get that fixed)

Thanks,  
Logan
