0

When I do a querytask and the date range criteria used is too vast, I get a 500 internal server error after 1.7 minutes every time (unless the query takes less than 1.7 minutes, then it runs fine). Is there any way I can use try, catch to let the user know the search has timed out.

I tried the following try, catch code but it does not do anything. It still says "Searching..." in my 'wait' div.

    function execute () {
            query.geometry = addressPoint;
            startDateQuery = document.getElementById("startDate").value
            endDateQuery = document.getElementById("endDate").value

            //esriConfig.defaults.io.timeout = 60,000;
            if (endDateQuery !== null && endDateQuery !== undefined && endDateQuery !== ""){
                query.where = "(DATE_VAL >= '" + startDateQuery + "') AND (DATE_VAL <= '" + endDateQuery + "')";
            }
            else {
                query.where = "DATE_VAL = '" + startDateQuery + "'";
            }
            try{
                queryTask.execute(query, showResults);
                document.getElementById('wait').innerHTML = "Searching...";
            }
            catch(err) {
                document.getElementById('wait').innerHTML = "Search timed out. Use a smaller search range.";
            }
        }
2

You would not have to define a try/catch statement. The QueryTask includes an error callback. You could just define that function and insert your code into it:

queryTask.execute(query, showResults, errCallback);

function errCallback(){
    document.getElementById('wait').innerHTML = "Search timed out. Use a smaller search range.";
}
0

The third parameter a QueryTask takes is a handler for error

try catch is not reliable in JavaScript because of its async nature

do it this way

queryTask.execute(query, showResults, function(){
  document.getElementById('wait').innerHTML = "Search timed out. Use a smaller search range.";
});

Or you may pass in a defined function just like showResults

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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