[gnome-maps/wip/mlundblad/handle-search-http-errors] graphHopperGeocode: Set HTTP timeout




commit 25c76a9dae4e02d753c85b8512735b7cf474487a
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 | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
---
diff --git a/src/graphHopperGeocode.js b/src/graphHopperGeocode.js
index e94442c2..f3f5134d 100644
--- a/src/graphHopperGeocode.js
+++ b/src/graphHopperGeocode.js
@@ -30,9 +30,12 @@ const PhotonParser = imports.photonParser;
 const Service = imports.service;
 const Utils = imports.utils;
 
+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 +54,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]