[gnome-maps/wip/routing2: 25/25] Fixup routeService (error handling)
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/routing2: 25/25] Fixup routeService (error handling)
- Date: Fri, 23 May 2014 17:00:58 +0000 (UTC)
commit ce55f477fbf5f9907e83c3d9270f97a39390c685
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Fri May 23 17:55:08 2014 +0100
Fixup routeService (error handling)
src/routeService.js | 114 +++++++++++++--------------------------------------
1 files changed, 29 insertions(+), 85 deletions(-)
---
diff --git a/src/routeService.js b/src/routeService.js
index 227e040..2d089d5 100644
--- a/src/routeService.js
+++ b/src/routeService.js
@@ -33,53 +33,6 @@ const RouteQuery = imports.routeQuery;
const EPAF = imports.epaf;
const HTTP = imports.http;
-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 GraphHopper = new Lang.Class({
Name: 'GraphHopper',
@@ -116,21 +69,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) {
+ // show inappnote: "Route not found." (maybe add "from {from} to {to}")
+ } 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;
+ // show inappnote: "Routing 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 +99,29 @@ 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;
},
_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]