From b7ec679560fb9ced0efcab6480d00a86e9982652 Mon Sep 17 00:00:00 2001 From: Philippe Troin Date: Fri, 24 May 2019 15:56:51 -0700 Subject: [PATCH] Handle DNS errors, retry in that case. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: JS ERROR: Gio.ResolverError: Error resolving “openweathermap.org”: Name or service not known _asyncReadyCallback@/usr/share/gnome-shell/extensions/openweather-extension@jenslody.de/extension.js:546:27 wrapper@resource:///org/gnome/gjs/modules/_legacy.js:82:22 --- src/extension.js | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/extension.js b/src/extension.js index 14c83eb..d39efa4 100644 --- a/src/extension.js +++ b/src/extension.js @@ -512,15 +512,34 @@ const OpenweatherMenuButton = new Lang.Class({ }, _checkConnectionState: function() { + this._checkConnectionStateRetries = 3; + this._oldConnected = this._connected; + this._connected = false; + + this._checkConnectionStateWithRetries(1250); + }, + + _checkConnectionStateRetry: function() { + if (this._checkConnectionStateRetries > 0) { + let timeout; + if (this._checkConnectionStateRetries == 3) + timeout = 10000; + else if (this._checkConnectionStateRetries == 2) + timeout = 30000; + else if (this._checkConnectionStateRetries == 1) + timeout = 60000; + + this._checkConnectionStateRetries -= 1; + this._checkConnectionStateWithRetries(timeout); + } + }, + + _checkConnectionStateWithRetries: function(interval) { if (this._timeoutCheckConnectionState) { Mainloop.source_remove(this._timeoutCheckConnectionState); this._timeoutCheckConnectionState = undefined; } - let interval = 1250; - this._oldConnected = this._connected; - this._connected = false; - this._timeoutCheckConnectionState = Mainloop.timeout_add(interval, Lang.bind(this, function() { // Delete (undefine) the variable holding the timeout-id, otherwise we can get errors, if we try to delete // it manually, the timeout will be destroyed automatically if we return false. @@ -535,13 +554,21 @@ const OpenweatherMenuButton = new Lang.Class({ } catch (err) { let title = _("Can not connect to %s").format(url); log(title + '\n' + err.message); + this._checkConnectionStateRetry(); } return false; })); }, _asyncReadyCallback: function(nm, res) { - this._connected = this._network_monitor.can_reach_finish(res); + try { + this._connected = this._network_monitor.can_reach_finish(res); + } catch (err) { + let title = _("Can not connect to %s").format(this.getWeatherProviderURL()); + log(title + '\n' + err.message); + this._checkConnectionStateRetry(); + return; + } if (!this._oldConnected && this._connected) { let now = new Date(); if (_timeCacheCurrentWeather &&