1

I have a loop that feeds the parameters to execute syncronymous geoprocessing services. When the loop runs it gives me the results when it receives valid params, and I get a generic error for the invalid params. The problem is that I need to know which params were invalid. It is very time-consuming to check manually which params are invalid when the loop runs over 1000 times. Is there way to customize the error message to include the params that caused the error?

this.gp = new Geoprocessor("http://xxx");
this.own(on(this.gp, 'execute-complete', lang.hitch(this, this.onExecutethis)));
        this.own(on(this.gp, 'error', lang.hitch(this, this.onError)));

onError: function (error) {
-----
}

-----
-----
for (i = 1; i < data.length; i++) {
    var params = {
              "var1": data[i][3],
              "var2": data[i][2]
            };
     this.gp.execute(params);
}

onExecutethis:function (results){
----
----
}

1 Answer 1

1

You could pass extra parameters to the error callback to figure out when the geoprocess fail. Try something like this,

for (let i = 1; i < data.length; i++) {
  var params = {
    "var1": data[i][3],
    "var2": data[i][2]
  };
  this.gp.execute(
    params,
    lang.hitch(this, this.onExecutethis),
    lang.hitch(this, function(error) { this.onError(error, i); })
  );
}

Check that I use let. If you are not using ES6, then I think this could work,

for (var i = 1; i < data.length; i++) {
  var params = {
    "var1": data[i][3],
    "var2": data[i][2]
  };
  this.gp.execute(
    params,
    lang.hitch(this, this.onExecutethis),
    lang.hitch(this, (function(error) {
      var j = i;
      return onError(error, j) { /*your function here*/ };
    })())
  );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.