[gnome-maps/gnome-3-38] graphHopperGeocode: Set HTTP timeout



commit 6d282d925b469567fbc987475e6fae1c051959c6
Author: Marcus Lundblad <ml update uu se>
Date:   Mon Sep 21 22:04:59 2020 +0200

    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);
+                }
             }
         });
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]