From 2ed67bdbf0855b5d58301e528eb5eee49d089cc6 Mon Sep 17 00:00:00 2001 From: Ondrej Date: Thu, 31 Jul 2014 17:54:43 +0200 Subject: [PATCH 1/2] Catching json parse errors now --- lib/nominatim.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/nominatim.js b/lib/nominatim.js index aad1283..d672fc1 100644 --- a/lib/nominatim.js +++ b/lib/nominatim.js @@ -19,7 +19,12 @@ function Nominatim() { queue.on('pop', function(item) { request(item.url + querystring.stringify(item.options), function(err, res) { - var results = JSON.parse(res.body); + try { + var results = JSON.parse(res.body); + } catch(error) { + var err = error; + var results = null; + } item.callback(err, item.options, results); }); From ea8df106be64f36ca65bc8fe08f3063b0103fd5e Mon Sep 17 00:00:00 2001 From: Ondrej Date: Thu, 31 Jul 2014 18:00:17 +0200 Subject: [PATCH 2/2] displaying response body as error when getting a json parse error --- lib/nominatim.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nominatim.js b/lib/nominatim.js index d672fc1..78264f4 100644 --- a/lib/nominatim.js +++ b/lib/nominatim.js @@ -22,7 +22,7 @@ queue.on('pop', function(item) { try { var results = JSON.parse(res.body); } catch(error) { - var err = error; + var err = new Error(res.body); var results = null; }