One issue I am encountering is when the server sends back empty XML without any data. Although most of the time everything works smoothly and as expected, sometimes this emptiness causes problems in processing the response.
var isokLayer = $http({
method: 'GET',
url: URLs.GEOSERVER_ISOK
}).then(function(response) {
if (response.status == 200) {
do {
var formatter = new ol.format.WMTSCapabilities();
} while (response.data == null);
var datas = (formatter.read(response.data));
var options = ol.source.WMTS.optionsFromCapabilities(datas, {
layer: 'CIEN',
matrixSet: 'EPSG:2180',
});
var source = new ol.source.WMTS(options);
for (var z = 0; z < source.getTileGrid().getMatrixIds().length; ++z) {
source.getTileGrid().getOrigin(z).reverse();
}
var result = new ol.layer.Tile({
source: source,
visible: false,
xarisLayerType: 'baseLayer',
xarisLayerName: 'NMT LPIS',
xarisLayerSampleIcon: 'assets/styles/img/baseLayerSample/nmt.png',
zIndex: ConfigService.getBaseLayerZIndex()
});
map.addLayer(result);
layerList.push(result);
} else {
console.log(response.status);
}
}, function(err) {
console.log(err);
});
I'm looking for a way to repeat the HTTP call within my successCallback function if the response data is null. I attempted to restart the process in the errorCallback, but due to the response.status always being 200, the error function never gets executed. Any suggestions on how to handle this scenario?