Skip to content

Commit

Permalink
fix: display a more usefull message when error in remote data (#2443)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanboniface authored Jan 24, 2025
2 parents 22846ac + 83c3a41 commit ea2bdba
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions umap/static/umap/js/modules/data/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@ export class DataLayer extends ServerStored {
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) {
if (!this.isRemoteLayer()) return
if (!this.hasDynamicData() && this.hasDataLoaded() && !force) return
Expand All @@ -310,13 +323,12 @@ export class DataLayer extends ServerStored {
if (this.options.remoteData.proxy) {
url = this._umap.proxyUrl(url, this.options.remoteData.ttl)
}
const response = await this._umap.request.get(url)
if (response?.ok) {
return await this.getUrl(url).then((raw) => {
this.clear()
return this._umap.formatter
.parse(await response.text(), this.options.remoteData.format)
.parse(raw, this.options.remoteData.format)
.then((geojson) => this.fromGeoJSON(geojson))
}
})
}

isLoaded() {
Expand Down Expand Up @@ -541,10 +553,9 @@ export class DataLayer extends ServerStored {

async importFromUrl(uri, type) {
uri = this._umap.renderUrl(uri)
const response = await this._umap.request.get(uri)
if (response?.ok) {
return this.importRaw(await response.text(), type)
}
return await this.getUrl(uri).then((raw) => {
return this.importRaw(raw, type)
})
}

getColor() {
Expand Down

0 comments on commit ea2bdba

Please sign in to comment.