From ee3fbac5703ea8a2b8ebe0f16a2be6f8d15c4545 Mon Sep 17 00:00:00 2001 From: Marcus Lundblad Date: Mon, 21 Sep 2020 22:04:59 +0200 Subject: [PATCH 1/4] graphHopperGeocode: Set HTTP timeout Set timeout on the SoupSession and activate the callback with the status code on errors. --- src/graphHopperGeocode.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/graphHopperGeocode.js b/src/graphHopperGeocode.js index e94442c2..e63877e4 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); + } } }); } -- GitLab From babb507d5d304d8152d04e089037635fda9fe1d4 Mon Sep 17 00:00:00 2001 From: Marcus Lundblad Date: Wed, 23 Sep 2020 22:01:09 +0200 Subject: [PATCH 2/4] photonGeocode: Set HTTP timeout Set timeout on the SoupSession and activate the callback with the status code on errors. --- src/photonGeocode.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/photonGeocode.js b/src/photonGeocode.js index 980e9b47..0de55dd2 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); + } } }); } -- GitLab From 8fd660a3f4681e1b0193bd0e3775a7f668a0a10c Mon Sep 17 00:00:00 2001 From: Marcus Lundblad Date: Mon, 21 Sep 2020 22:44:56 +0200 Subject: [PATCH 3/4] placePopover: Add error state Add an error state and a function to display the error state when a search has failed. --- data/ui/place-popover.ui | 12 ++++++++++++ src/placePopover.js | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/data/ui/place-popover.ui b/data/ui/place-popover.ui index ae663a17..e04114bb 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/placePopover.js b/src/placePopover.js index d3c1d006..72917423 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; -- GitLab From 64861992de500d4efae4cff4162889a8e3122eb0 Mon Sep 17 00:00:00 2001 From: Marcus Lundblad Date: Tue, 22 Sep 2020 22:21:41 +0200 Subject: [PATCH 4/4] placeEntry: Show error message on search failure --- src/placeEntry.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/placeEntry.js b/src/placeEntry.js index a1c4501a..494784d9 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) -- GitLab