fix: display a more usefull message when error in remote data

fix #2379
This commit is contained in:
Yohan Boniface 2025-01-23 12:04:25 +01:00
parent 30690bcb35
commit 83c3a41be5

View file

@ -302,6 +302,19 @@ export class DataLayer extends ServerStored {
return this.isRemoteLayer() && Boolean(this.options.remoteData?.dynamic) return this.isRemoteLayer() && Boolean(this.options.remoteData?.dynamic)
} }
async getUrl(url) {
const response = await this._umap.request.get(url)
return new Promise((resolve) => {
if (response?.ok) return resolve(response.text())
Alert.error(
translate('Cannot load remote data for layer "{layer}" with url "{url}"', {
layer: this.getName(),
url: url,
})
)
})
}
async fetchRemoteData(force) { async fetchRemoteData(force) {
if (!this.isRemoteLayer()) return if (!this.isRemoteLayer()) return
if (!this.hasDynamicData() && this.hasDataLoaded() && !force) return if (!this.hasDynamicData() && this.hasDataLoaded() && !force) return
@ -310,13 +323,12 @@ export class DataLayer extends ServerStored {
if (this.options.remoteData.proxy) { if (this.options.remoteData.proxy) {
url = this._umap.proxyUrl(url, this.options.remoteData.ttl) url = this._umap.proxyUrl(url, this.options.remoteData.ttl)
} }
const response = await this._umap.request.get(url) return await this.getUrl(url).then((raw) => {
if (response?.ok) {
this.clear() this.clear()
return this._umap.formatter return this._umap.formatter
.parse(await response.text(), this.options.remoteData.format) .parse(raw, this.options.remoteData.format)
.then((geojson) => this.fromGeoJSON(geojson)) .then((geojson) => this.fromGeoJSON(geojson))
} })
} }
isLoaded() { isLoaded() {
@ -541,10 +553,9 @@ export class DataLayer extends ServerStored {
async importFromUrl(uri, type) { async importFromUrl(uri, type) {
uri = this._umap.renderUrl(uri) uri = this._umap.renderUrl(uri)
const response = await this._umap.request.get(uri) return await this.getUrl(uri).then((raw) => {
if (response?.ok) { return this.importRaw(raw, type)
return this.importRaw(await response.text(), type) })
}
} }
getColor() { getColor() {