Before my code runs, I would like to evaluate if a web service is running. How would I do that in JavaScript?
I just wanted to evaluate the URL. All the information should exist independent of my application running, so I wanted to check if I could see any information before consuming the service.
I'm currently not receiving any error messages when I paste in the URL for a stopped service. Any ideas?
Okay, I have my service stopped right now at: test/StreetSignTest (FeatureServer)
The URL does not provide an error by opening the page; it just shows up as blank.
I'm unsure, but could you check by pulling the first layer?
http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0
Yes, my recommendation is to use the layer and return json: http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0?f=json.
If you just hit the feature service it returns a 200. Not sure why, but that's why you aren't getting an error.
I think that is the right way to go. I got the following message when I tried that layer:
Error: Error handling service request : Could not find a service with the name 'test/MapServer/StreetSignTest' in the configured clusters. Service may be stopped or ArcGIS Server may not be running.
Code: 500
So, do you or Andy Gup know what I should write to evaluate an error of 500 in my code for that URL? I have looked up how to read JSON responses, but I can find code to evaluate this.
Chris,
Use esriRequest.
var requestHandle = esriRequest({ url: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0", content: { f: 'json' }, handleAs: "json" }); requestHandle.then(function(lyrJSON, io){ console.info(lyrJSON); }
This one I could not get to work. It just errored out if a web service was not running but did not write to the console log.
Chris,
OK, I forgot you were looking for the error.
Try this:
requestHandle.then( function(lyrJSON, io){ console.info(lyrJSON); }, function(err){ console.info(err); } );
I might have modified it incorrectly; here is what I updated and still get an error with a stopped web service:
var requestHandle = esriRequest({ url: "http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0", content: { f: 'json' }, handleAs: "json" }); requestHandle.then( function (lyrJSON, io) { console.info(lyrJSON); }, function (err) { console.info(err); } );