retry wikidata api without lng's region subtag if an error is returned

closes #9638
This commit is contained in:
Martin Raifer
2023-05-23 16:04:33 +02:00
parent 559a4ba728
commit 862ca6522a
2 changed files with 13 additions and 3 deletions
+3
View File
@@ -48,6 +48,8 @@ _Breaking developer changes, which may affect downstream projects or sites that
* Fix wrongly flagged "incorrect geometry type" warnings for features with lifecycle-prefixed tags ([#9483], thanks [@biswajit-k])
* Fix corruption of tag values of fields with referenced strings, but restricted `options`, when an unavailable option is entered manually into the field.
* Properly handle case sensitive tag values in taginfo suggestions in raw tag editor ([#9640])
* Fix dysfunctional autocomplete of wikidata fields for some languages with country-codes ([#9638])
#### :earth_asia: Localization
* Send `Accept-Language` header on Nominatim API calls ([#9501], thanks [@k-yle])
* Add Address and Phone Format for India ([#9482], thanks [@biswajit-k])
@@ -68,6 +70,7 @@ _Breaking developer changes, which may affect downstream projects or sites that
[#9493]: https://github.com/openstreetmap/iD/pull/9493
[#9520]: https://github.com/openstreetmap/iD/pull/9520
[#9501]: https://github.com/openstreetmap/iD/pull/9501
[#9638]: https://github.com/openstreetmap/iD/pull/9638
[#9640]: https://github.com/openstreetmap/iD/issues/9640
[@biswajit-k]: https://github.com/biswajit-k
+10 -3
View File
@@ -17,13 +17,13 @@ export default {
// Search for Wikidata items matching the query
itemsForSearchQuery: function(query, callback) {
itemsForSearchQuery: function _itemsForSearchQuery(query, callback, language) {
if (!query) {
if (callback) callback('No query', {});
return;
}
var lang = this.languagesToQuery()[0];
var lang = language || this.languagesToQuery()[0];
var url = apibase + utilQsString({
action: 'wbsearchentities',
@@ -42,7 +42,14 @@ export default {
d3_json(url)
.then(function(result) {
if (result && result.error) {
throw new Error(result.error);
if (result.error.code === 'badvalue' &&
result.error.info.includes(lang) &&
!language && lang.includes('-')) {
// retry without "country suffix" region subtag
_itemsForSearchQuery(query, callback, lang.split('-')[0]);
} else {
throw new Error(result.error);
}
}
if (callback) callback(null, result.search || {});
})