Hi Guys,
I am trying to detect errors when adding layers to a map. I am sending a url to a webservice to get layer info, I'm intentionally firing out an incorrect url so that the response returns a 500 error. is there any way i can catch the response from the webservice and trigger an error when this response is recieved?
firstLayer = new esri.layers.ArcGISDynamicMapServiceLayer(lincorrectUrl);
Thanks,
Don
Solved! Go to Solution.
Don,
Here is a sample that shows error handling:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Simple Map</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.17/esri/css/esri.css">
<style>
html, body, #map {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script src="https://js.arcgis.com/3.17/"></script>
<script>
var map;
require(["esri/map", "esri/layers/ArcGISDynamicMapServiceLayer", "dojo/domReady!"], function(Map, ArcGISDynamicMapServiceLayer) {
map = new Map("map", {
basemap: "topo", //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wd
center: [-122.45, 37.75], // longitude, latitude
zoom: 13
});
var incorrectUrl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville2/LOJIC_LandRecords_Louisville/..."
var firstLayer = new ArcGISDynamicMapServiceLayer(incorrectUrl);
firstLayer.on('error', function(error){
console.info(error);
});
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
Hi Donnagh,
It helps if you mention what programming language you are dealing with and really helps when you place your post in a "Space" that indicates your topic (like https://community.esri.com/community/developers?sr=search&searchId=9ae26d84-1fff-4933-a74b-413038205... but hopefully more specific than that, like https://community.esri.com/community/developers/web-developers/arcgis-api-for-javascript?sr=search&s...). The Community Help space is for help with the GeoNet and general topics.
Don,
Here is a sample that shows error handling:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Simple Map</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.17/esri/css/esri.css">
<style>
html, body, #map {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script src="https://js.arcgis.com/3.17/"></script>
<script>
var map;
require(["esri/map", "esri/layers/ArcGISDynamicMapServiceLayer", "dojo/domReady!"], function(Map, ArcGISDynamicMapServiceLayer) {
map = new Map("map", {
basemap: "topo", //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wd
center: [-122.45, 37.75], // longitude, latitude
zoom: 13
});
var incorrectUrl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Louisville2/LOJIC_LandRecords_Louisville/..."
var firstLayer = new ArcGISDynamicMapServiceLayer(incorrectUrl);
firstLayer.on('error', function(error){
console.info(error);
});
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
Hi Robert,
This is exactly what I was looking for, I struggled to find examples in the documentation, apologies for the lack of original info.
Thanks,
Donnagh
Donnagh,
Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.