diff --git a/data/ui/place-popover.ui b/data/ui/place-popover.ui index ae663a17a1a9c0d0a2a5f8bb0f6c473d3aadb394..e04114bb63a66acf1d653ecb26fb2e6753d2ec83 100644 --- a/data/ui/place-popover.ui +++ b/data/ui/place-popover.ui @@ -59,6 +59,18 @@ + + + True + False + An error has occurred + 16 + 16 + + + diff --git a/src/graphHopperGeocode.js b/src/graphHopperGeocode.js index e94442c204d1a25c0bef0ebe0400b78889257403..e63877e4d74ce9a09f58e0dae202254fac7356ab 100644 --- a/src/graphHopperGeocode.js +++ b/src/graphHopperGeocode.js @@ -30,9 +30,14 @@ const PhotonParser = imports.photonParser; const Service = imports.service; const Utils = imports.utils; +// HTTP session timeout (in seconds) +const TIMEOUT = 5; + var GraphHopperGeocode = class { constructor() { - this._session = new Soup.Session({ user_agent : 'gnome-maps/' + pkg.version }); + this._session = + new Soup.Session({ user_agent : 'gnome-maps/' + pkg.version, + timeout: TIMEOUT }); this._readService(); this._limit = Application.settings.get('max-search-results'); } @@ -51,15 +56,19 @@ var GraphHopperGeocode = class { if (cancellable.is_cancelled()) return; - try { - let result = this._parseMessage(message.response_body.data); - if (!result) - callback(null, null); - else - callback(result, null); - } catch (e) { - Utils.debug('Error: ' + e); - callback(null, e); + if (message.status_code !== Soup.KnownStatusCode.OK) { + callback(null, msg.status_code); + } else { + try { + let result = this._parseMessage(message.response_body.data); + if (!result) + callback(null, null); + else + callback(result, null); + } catch (e) { + Utils.debug('Error: ' + e); + callback(null, e); + } } }); } diff --git a/src/photonGeocode.js b/src/photonGeocode.js index 980e9b476bc3e13cbf9a15ad9dd87647b6edced7..0de55dd27cbabd469ce42e741430f4492532ee23 100644 --- a/src/photonGeocode.js +++ b/src/photonGeocode.js @@ -30,9 +30,14 @@ const PhotonParser = imports.photonParser; const Service = imports.service; const Utils = imports.utils; +// HTTP session timeout (in seconds) +const TIMEOUT = 5; + var PhotonGeocode = class { constructor() { - this._session = new Soup.Session({ user_agent : 'gnome-maps/' + pkg.version }); + this._session = + new Soup.Session({ user_agent : 'gnome-maps/' + pkg.version, + timeout: TIMEOUT }); this._readService(); this._limit = Application.settings.get('max-search-results'); } @@ -50,15 +55,19 @@ var PhotonGeocode = class { if (cancellable.is_cancelled()) return; - try { - let result = this._parseMessage(message.response_body.data); - if (!result) - callback(null, null); - else - callback(result, null); - } catch (e) { - Utils.debug('Error: ' + e); - callback(null, e); + if (message.status_code !== Soup.KnownStatusCode.OK) { + callback(null, msg.status_code); + } else { + try { + let result = this._parseMessage(message.response_body.data); + if (!result) + callback(null, null); + else + callback(result, null); + } catch (e) { + Utils.debug('Error: ' + e); + callback(null, e); + } } }); } diff --git a/src/placeEntry.js b/src/placeEntry.js index a1c4501ac34a3100f7da8ade6604a256c076b60d..494784d9a03492c71e33a25c4ffb2cd34b9d9903 100644 --- a/src/placeEntry.js +++ b/src/placeEntry.js @@ -258,10 +258,16 @@ var PlaceEntry = GObject.registerClass({ this._cancellable, (places, error) => { this._cancellable = null; - this._updateResults(places); - // cache results for later - this._cache[this.text] = places; + if (error) { + this.place = null; + this._popover.showError(); + } else { + this._updateResults(places); + + // cache results for later + this._cache[this.text] = places; + } // if search input has been updated, trigger a refresh if (this.text !== this._previousSearch) diff --git a/src/placePopover.js b/src/placePopover.js index d3c1d0062a3af1b57eb40baaf8c8472389492b00..72917423261d5fe834cf44d7ab322af2bdd28c73 100644 --- a/src/placePopover.js +++ b/src/placePopover.js @@ -36,7 +36,8 @@ var PlacePopover = GObject.registerClass({ 'stack', 'spinner', 'list', - 'noResultsLabel' ], + 'noResultsLabel', + 'errorLabel' ], }, class PlacePopover extends SearchPopover.SearchPopover { _init(props) { @@ -101,6 +102,13 @@ var PlacePopover = GObject.registerClass({ this._stack.visible_child = this._noResultsLabel; } + showError() { + if (this._spinner.active) + this._spinner.stop(); + + this._stack.visible_child = this._errorLabel; + } + updateResult(places, searchString) { let i = 0;