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.";
 }
 }
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Feb 5, 2015 at 15:14

2 Answers 2

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.";
}
answered Feb 5, 2015 at 15:23
0
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

answered Feb 5, 2015 at 15:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.