0

I'm attempting to program a browser-based medical image viewer and am using the XTK library to do the heavy lifting. When a file does not load properly (for any number of reasons) I want to let the user know with a pop-up message (eg saying 'File could not be loaded'). From what I can tell though, all the error handling/throwing happens deep down in the loader.js or parser.js files.

More specifically, when I download this file and try loading it with Slicedrop, I get the following error in the console:

Uncaught Error: invalid file signature:

This error is thrown in gunzip.js. At other times, I've had:

Uncaught Error: Loading failed:

thrown in loader.js.

Does anyone know how I could go about catching or passing these errors higher up the chain (ie in JavaScript code like in XTK Tutorial 13?). I've tried the following:

try 
    sliceX.render();
catch(err)
    console.log('ERROR');

But this doesn't catch any errors (due to the asynchronous nature of the file loading I imagine).

The X.renderer has a onShowtime function which is called when all loading has completed. I would imagine a similar function like onLoadError or some other loadingError event?

David Basalla
  • 2,996
  • 3
  • 18
  • 22

1 Answers1

0

One solution that I can think of is to add something like the code below where I can query the error message to see if they match the specific errors thrown by a bad file load:

<script  type="text/javascript">
  window.onerror = function (errorMsg, url, lineNumber) {

  if(errowMsg == 'invalid file signature')
      alert(errorMsg);
  };
</script>

Feels quite hacky though...? Would be great to get another opinion

Cheers

Dave

David Basalla
  • 2,996
  • 3
  • 18
  • 22