[gnome-maps/wip/mlundblad/handle-search-http-errors: 2/5] graphHopperGeocode: 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/5] graphHopperGeocode: Set HTTP timeout
- Date: Mon, 28 Sep 2020 20:36:38 +0000 (UTC)
commit 883b0999815daabda1d7144639e3df5f41eb2254
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 | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/src/graphHopperGeocode.js b/src/graphHopperGeocode.js
index e94442c2..04ca38cb 100644
--- a/src/graphHopperGeocode.js
+++ b/src/graphHopperGeocode.js
@@ -30,9 +30,13 @@ 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 +55,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]