[gnome-maps/wip/mlundblad/handle-search-http-errors: 2/4] photonGeocode: Set HTTP timeout
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/handle-search-http-errors: 2/4] photonGeocode: Set HTTP timeout
- Date: Wed, 23 Sep 2020 20:04:26 +0000 (UTC)
commit a6b23f939646ef23f662247dcbd508ea22900901
Author: Marcus Lundblad <ml update uu se>
Date: Wed Sep 23 22:01:09 2020 +0200
photonGeocode: Set HTTP timeout
Set timeout on the SoupSession and activate the
callback with the status code on errors.
src/photonGeocode.js | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/src/photonGeocode.js b/src/photonGeocode.js
index 980e9b47..af1c4a12 100644
--- a/src/photonGeocode.js
+++ b/src/photonGeocode.js
@@ -30,6 +30,9 @@ 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 });
@@ -50,15 +53,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);
+ }
}
});
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]