[GIS] Esri ArcGIS JavaScript – printTask.execute issues with error

arcgis-javascript-apiprinting

I'm using the ArcGIS JavaScript API 3.18.

The print service is configured to be async, with a timeout of 10 minutes.

The code to call the job is as follows:

  printTask.execute(printParameters,
      function (result) {
          $log.debug('Esri portion of print task complete...');
          var exportedMapUrl = result.url;
          onComplete({ url: exportedMapUrl });
      },
      function (errorResult) {
          $log.info(errorResult);
          onError({ message: errorResult, details: [] });
      });
  });

If I intentionally cause an error, i.e. by disabling the print service, the error callback is triggered and all is good, however if I execute a complex print task, which takes >10 minutes (that's another story) and the task times out, nothing is triggered. i.e. if I look in the network tab of Chrome dev tools, I can see that the arcgis api is polling every second or so, and eventually the status
jobStatus:"esriJobFailed"
is returned, however this seems to be eaten by the arcgis api, and nothing is raised in my code – how can I trap a timeout? This seems to be a pretty fundamental "error" that just disappears and it's difficult for me to surface this to the user.

Edit

This is just using the standard print service, with slightly modified templates. The process succeeds when A4, A3 & A1 are selected, and also when a less complex A0 map is printed (i.e. less layers).

Best Answer

Your error callback should fire in the event of the GP task failing...Have you verified that the GP Service works and that you matched the required parameters of the PrintTask in the GP Tool (I only ask because I know it is very picky)? Checking the ArcGIS Server log files should show what is actually throwing the error in the back end.

As for the JS side of things, one thing you could try is to hook into the complete and error events:

// on is 'dojo/on'
var pt = printTask.execute(printParameters);

on(pt, 'complete', function(dataFile){
  // do something with dataFile such as download link
});

on(pt, 'error', function(error){
  $log.info(errorResult);
  console.log('error: ', error);
});
Related Question