11 Replies Latest reply on Jul 20, 2018 8:18 AM by Matt Bark

    Javascript API - catching errors

    Benoit Boireau

      Hello,

       

      I use the javascript API to embed views from Tableau Server, and I wonder how I can catch the errors thrown by the server (Tableau internal errors, or errors that occur when the client lose its network connection for example) : I would like my application to be aware of these errors.

       

      The documentation is missing an example about this : I don't understand where do I need to put my try/catch block, as all my calls to the API are asynchronous.

      Has someone already done this ?

      Thanks for you help,

       

      Regards,

      Benoît

        • 1. Re: Javascript API - catching errors
          Nay Lin Soe

          Hi Benoît,

           

          I'm exactly in the same boat as yours. I use JS API to embed dashboards. Time to time, I get '500 Internal Server Error' from Tableau Server. However, I haven't found a way of handling that error, i.e. my application detecting it and reponding appropriately. I can see the error only because I have got Firebug installed.

           

          As I understand, the viz is loaded asynchronously when

          new tableauSoftware.Viz(placeholderDiv, url, options)

           

          is executed. In 'option' we can attach a function to 'onFirstInteractive' which is roughly equivalent to 'success' call back. But there is no option to attach a function when errors like this occurs. I've tried putting the above in try-catch block, but no exceptions are thrown.

           

          So I am very keen to know as well how to handle these network errors. Could anyone from Tableau help us out please? Thanks.

           

          Nay

          • 2. Re: Javascript API - catching errors
            Ryan Grant

            Similar boat as well. In my case, if I initialize a new viz object for a user who does not have permission to view the report, the "onFirstInteractive" success callback is never called and no exceptions are thrown. The report does not load at all and a 404 is thrown on the GET request of the viz url. Nothing ends up getting displayed to the user within the frame.

             

            Would be nice to catch these errors in an error callback passed in via the options parameter object so we can display a message that the user does not have permissions for given report.  Using the rest api to check if a user has permissions prior to loading is not an option for us.

            • 3. Re: Javascript API - catching errors
              Meet Idnani

              I need to do a similar thing. I need to show/hide "Loading .." image while the report is loading... I can show the image on my report url call and hide it inside the onFirstInteractive. But in cases where the viz is not initialized due to permission or session expiration i am stuck at the "Loading " screen as onFirstInteractive is never called.

               

              Im using a timeout workaround as of now, but i need a more concrete solution.

               

              Some help please

              • 4. Re: Javascript API - catching errors
                Brian McNamara

                Does anyone know of a solution to this issue? 

                • 5. Re: Javascript API - catching errors
                  J McGrath

                  Has anyone got a solution to this yet?  I need to catch errors also as on loading the graphs first time I get a Forbidden Access error but then on a refresh it goes away so want to catch this and refresh automatically..

                  • 6. Re: Javascript API - catching errors
                    Kurt Fredericks

                    I would love to get some support on this as well.

                     

                    I would like to be able to catch a post 404 and 410 error that the server gives when a Tableu Server connection goes idle. I've tried catching global errors through window.onerror in my javascript but that doesn't seem to be catching Tableau Server errors.

                     

                    Please advise.

                    • 7. Re: Javascript API - catching errors
                      David Brear

                      So I might have found a workaround until Tableau gets a better answer but if you attach an event listener to the window and listen for 'message', you can catch messages coming back. I created 2 reports, one I had access to and the other I did not have permissions to view and when you look at the one with permissions, the message 'tableau.completed' comes back but is the only message. On the other hand, when I access the view I have permission to see, the window comes back with a 'tableau.loadIndicatorsLoaded' several times followed by a 'tableau.completed,-1,handler0'. I know it's hacky but this worked for me:

                      /* convenience method to eliminate need to check for extra params. */

                      function isMessage(txt, msg) {

                        return txt.substring(0, msg.length) === msg;

                      }

                      function initializeViz() {

                        var placeholderDiv = document.getElementById("tableauViz");

                       

                        var vizLoaded = false;

                      // these are just constants for the messages returned.

                        var LOADED_INDICATOR = 'tableau.loadIndicatorsLoaded'; 

                        var COMPLETE_INDICATOR = 'tableau.completed';

                        var options = {

                          width: placeholderDiv.offsetWidth,

                          height: placeholderDiv.offsetHeight,

                          hideTabs: true,

                          hideToolbar: true,

                          onFirstInteractive: function (e) {

                            workbook = viz.getWorkbook();

                            activeSheet = workbook.getActiveSheet();

                          }

                        };

                        viz = new tableau.Viz(placeholderDiv, url, options);

                        window.addEventListener('message', function(msg) {

                          if (isMessage(msg.data, LOADED_INDICATOR)) {

                            vizLoaded = true;

                          } else if (isMessage(msg.data, COMPLETE_INDICATOR)){

                            if (vizLoaded) {

                              alert('viz loaded successfully!');

                            } else {

                              alert('viz failed to load!');

                            }

                          }

                        });

                      }

                       

                      Hope this helps!

                      5 of 5 people found this helpful
                      • 8. Re: Javascript API - catching errors
                        Kurt Fredericks

                        Whoa, cool--thanks for sharing, David!

                         

                        I'll test this out within the next week or two; but I would love to be able to add this functionality to my Web app.

                        • 9. Re: Javascript API - catching errors
                          Shabeer Sheffa

                          I've tried the solution and it works as expected.

                          • 10. Re: Javascript API - catching errors
                            Aaron Freeland

                            Not sure how this is still considered the acceptable solution after 3+ years?  Subscribing to 'message' when dealing with multiple tableaus viz's on a page just seems like banana land...

                             

                            Has anyone come up with a more graceful way of handling this yet?

                            • 11. Re: Javascript API - catching errors
                              Matt Bark

                              I'm now running into errors when a dashboard is restricted by site level permissions. The iframe renders a login prompt but I need to know in my app because I try to assist the user when errors occur. Absolutely no way to catch the exception, and it's trivial to patch in a handler for it so why has this issue not been resolved yet? I'm trying to use the vanilla version of the library but it's frustrating when it lacks so much basic functionality.

                               

                              Uncaught TypeError: Cannot read property 'width' of null     at bF.handleVizLoad (tableau-2.2.0.min.js:formatted:7218)     at b.$4 (tableau-2.2.0.min.js:formatted:4754)     at b.$1 (tableau-2.2.0.min.js:formatted:4700)     at delegate (tableau-2.2.0.min.js:formatted:759)