maps: handle empty geojson (#58283)

This commit is contained in:
Valentin Deniaud 2021-11-02 12:04:57 +01:00
parent a3d180eee9
commit a4b2cecd0f
2 changed files with 11 additions and 0 deletions

View File

@ -241,6 +241,12 @@ class MapLayer(models.Model):
'features': [],
'_combo_err_desc': "Non JSON response from requested URL",
}
if data is None:
return {
'type': 'FeatureCollection',
'features': [],
'_combo_err_desc': "Empty JSON response",
}
if 'features' in data:
features = data['features']
else:

View File

@ -304,6 +304,11 @@ def test_get_geojson(app, layer, user):
assert len(resp.json['features']) == 0
assert resp.json['_combo_err_desc'] == 'Non JSON response from requested URL'
mock_resp.json = lambda: None
resp = app.get(geojson_url)
assert len(resp.json['features']) == 0
assert resp.json['_combo_err_desc'] == 'Empty JSON response'
mock_resp.status_code = 500
resp = app.get(geojson_url)
assert len(resp.json['features']) == 0