[gnome-maps/wip/routing2] Fixup routeService (error handling)
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/routing2] Fixup routeService (error handling)
- Date: Fri, 23 May 2014 17:16:10 +0000 (UTC)
commit 4356eeca05d4fc5fd2335d0bf5d4625263e69f6d
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Fri May 23 17:55:08 2014 +0100
Fixup routeService (error handling)
src/routeService.js | 133 +++++++++++++++++---------------------------------
1 files changed, 45 insertions(+), 88 deletions(-)
---
diff --git a/src/routeService.js b/src/routeService.js
index 227e040..a562d0b 100644
--- a/src/routeService.js
+++ b/src/routeService.js
@@ -20,65 +20,21 @@
* Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
*/
-const Soup = imports.gi.Soup;
const Champlain = imports.gi.Champlain;
const GLib = imports.gi.GLib;
+const Soup = imports.gi.Soup;
const Lang = imports.lang;
-const Utils = imports.utils;
const _ = imports.gettext.gettext;
-const Route = imports.route;
-const RouteQuery = imports.routeQuery;
+const Application = imports.application;
const EPAF = imports.epaf;
const HTTP = imports.http;
+const Route = imports.route;
+const RouteQuery = imports.routeQuery;
+const Utils = imports.utils;
-const RouteError = new Lang.Class({
- Name: 'RouteError',
-
- _init: function(message, debugMessages) {
- this._message = message;
- this._debugMessages = debugMessages;
- },
-
- debug: function() {
- this._debugMessages.forEach(Utils.debug);
- },
-
- toString: function() {
- return this._message;
- }
-});
-
-const ParseMsgError = new Lang.Class({
- Name: 'ParseMsgError',
- Extends: RouteError,
-
- _init: function(httpCode, httpBody, errors) {
- let debugMsgs = ["HTTP code: " + httpCode];
- if(errors.length > 0) {
- debugMsgs.push("Errors: {");
- errors.forEach(function({ details, msg }, i) {
- debugMsgs.push(" Message[" + (i + 1) + "]: " + msg);
- debugMsgs.push(" Details[" + (i + 1) + "]: " + details);
- });
- debugMsgs.push("}");
- }
- debugMsgs.push("HTTP Body: {\n" + httpBody + "\n}");
- this.parent(_("The route search result had error(s)."),
- debugMsgs);
- }
-});
-
-const CreateRouteError = new Lang.Class({
- Name: 'CreateRouteError',
- Extends: RouteError,
-
- _init: function(path) {
- this.parent(_("Couldn't parse the route result JSON."),
- [JSON.stringify(path)]);
- }
-});
+const NoRouteFoundMessage = "No route found from %s to %s";
const GraphHopper = new Lang.Class({
Name: 'GraphHopper',
@@ -116,21 +72,21 @@ const GraphHopper = new Lang.Class({
this._session.queue_message(msg, (function(session, message) {
try {
let result = this._parseMessage(message);
- let route = this._createRoute(result);
- this.route.update(route);
+ if(result.info && result.info.errors) {
+ Application.notificationManager.showMessage(_("No route found."));
+ } else {
+ let route = this._createRoute(result.paths[0]);
+ this.route.update(route);
+ }
} catch(e) {
- if(e instanceof RouteError) {
- log(e);
- e.debug();
- } else
- throw e;
+ Application.notificationManager.showMessage(_("Route request failed."));
}
}).bind(this));
},
_buildURL: function(viaPoints, transportation) {
- let points = viaPoints.map(function(p) {
- return [p.latitude, p.longitude].join(',');
+ let points = viaPoints.map(function({ latitude, longitude }) {
+ return [latitude, longitude].join(',');
});
let vehicle = RouteQuery.Transportation.toString(transportation);
let query = new HTTP.Query({ type: 'json',
@@ -146,38 +102,39 @@ const GraphHopper = new Lang.Class({
},
_parseMessage: function({ status_code, response_body }) {
- let errors = [];
- if (status_code === 200 && response_body) {
- let result = JSON.parse(response_body.data);
- let info = result.info;
- let paths = result.paths;
- if(paths && paths[0])
- return paths[0];
- else if(info && info.errors) {
- errors = info.errors;
- }
- }
- throw new ParseMsgError(status_code, response_body.data, errors);
+ if (status_code === 200)
+ return JSON.parse(response_body.data);
+
+ if(status_code === 500)
+ this._logInternalServerError(response_body);
+
+ return null;
+ },
+
+ _logInternalServerError: function(body) {
+ // TODO: log
+ /*
+
+ Internal server error. It is strongely
+ recommended to send us the message and the link
+ to it, as it is very likely a bug in our system.
+ */
},
_createRoute: function(result) {
- try {
- let path = EPAF.decode(result.points);
- let turnPoints = this._createTurnPoints(path, result.instructions);
- let bbox = new Champlain.BoundingBox();
-
- // GH does lonlat-order and Champlain latlon-order
- bbox.extend(result.bbox[1], result.bbox[0]);
- bbox.extend(result.bbox[3], result.bbox[2]);
-
- return { path: path,
- turnPoints: turnPoints,
- distance: result.distance,
- time: result.time,
- bbox: bbox };
- } catch (e) {
- throw new CreateRouteError(result);
- }
+ let path = EPAF.decode(result.points);
+ let turnPoints = this._createTurnPoints(path, result.instructions);
+ let bbox = new Champlain.BoundingBox();
+
+ // GH does lonlat-order and Champlain latlon-order
+ bbox.extend(result.bbox[1], result.bbox[0]);
+ bbox.extend(result.bbox[3], result.bbox[2]);
+
+ return { path: path,
+ turnPoints: turnPoints,
+ distance: result.distance,
+ time: result.time,
+ bbox: bbox };
},
_createTurnPoints: function(path, instructions) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]