Skip to content

Commit

Permalink
fix(core): extra error handling on failed layer
Browse files Browse the repository at this point in the history
if a layer is down, it appears sometimes the attribute fetch will
not hit the fail block, but will return as success with an error message
add extra code to catch this case.  bug was not logged, no closes.
  • Loading branch information
james-rae committed May 26, 2015
1 parent e403ab7 commit b3e55a4
Showing 1 changed file with 47 additions and 40 deletions.
87 changes: 47 additions & 40 deletions src/js/RAMP/Modules/attributeLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,49 +171,56 @@ define([
});

defService.then(function (serviceResult) {
RampMap.updateDatagridUpdatingState(RAMP.layerRegistry[layerId], true);

//set up layer data object based on layer data
var maxBatchSize = serviceResult.maxRecordCount || -1, //10.0 server will not supply a max record value
defFinished = new Deferred(),
layerData = newLayerData();
layerData.layerId = layerId;

//find object id field
serviceResult.fields.every(function (elem) {
if (elem.type === 'esriFieldTypeOID') {
layerData.idField = elem.name;
return false; //break the loop
if (serviceResult && (typeof serviceResult.error === 'undefined')) {
RampMap.updateDatagridUpdatingState(RAMP.layerRegistry[layerId], true);

//set up layer data object based on layer data
var maxBatchSize = serviceResult.maxRecordCount || -1, //10.0 server will not supply a max record value
defFinished = new Deferred(),
layerData = newLayerData();
layerData.layerId = layerId;

//find object id field
serviceResult.fields.every(function (elem) {
if (elem.type === 'esriFieldTypeOID') {
layerData.idField = elem.name;
return false; //break the loop
}
return true; //keep looping
});

//begin the loading process
loadDataBatch(-1, maxBatchSize, layerUrl, layerData.idField, layerId, defFinished);

//after all data has been loaded
defFinished.promise.then(function (features) {
addLayerData(layerData, features);

//store attribData
// (Set layer data in global object only once all data has been downloaded
// Used as both a flag and a data store)
RAMP.data[layerId] = layerData;
//new data. tell grid to reload
topic.publish(EventManager.Datagrid.APPLY_EXTENT_FILTER);

RampMap.updateDatagridUpdatingState(RAMP.layerRegistry[layerId], false);
console.log('END ATTRIB LOAD: ' + layerId);
},
function (error) {
console.log('error getting attribute data for id ' + layerId);
//set layer to error state
RampMap.updateDatagridUpdatingState(RAMP.layerRegistry[layerId], false);
topic.publish(EventManager.LayerLoader.LAYER_ERROR, { layer: RAMP.layerRegistry[layerId], error: error });
});
} else {
console.log('Service metadata load error');
if (serviceResult && serviceResult.error) {
console.log(serviceResult.error);
}
return true; //keep looping
});

//begin the loading process
loadDataBatch(-1, maxBatchSize, layerUrl, layerData.idField, layerId, defFinished);

//after all data has been loaded
defFinished.promise.then(function (features) {
addLayerData(layerData, features);

//store attribData
// (Set layer data in global object only once all data has been downloaded
// Used as both a flag and a data store)
RAMP.data[layerId] = layerData;
//new data. tell grid to reload
topic.publish(EventManager.Datagrid.APPLY_EXTENT_FILTER);

RampMap.updateDatagridUpdatingState(RAMP.layerRegistry[layerId], false);
console.log('END ATTRIB LOAD: ' + layerId);
},
function (error) {
console.log('error getting attribute data for id ' + layerId);
//set layer to error state
RampMap.updateDatagridUpdatingState(RAMP.layerRegistry[layerId], false);
topic.publish(EventManager.LayerLoader.LAYER_ERROR, { layer: RAMP.layerRegistry[layerId], error: error });
});
}
},
function (error) {
console.log('Max Record count load error : ' + error);
console.log('Service metadata load error : ' + error);
});

break;
Expand Down

0 comments on commit b3e55a4

Please sign in to comment.