mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-19 23:14:47 +02:00
retry wikidata api without lng's region subtag if an error is returned
closes #9638
This commit is contained in:
@@ -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 || {});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user