Skip to content
Browse files

Avoid exception when parsing json.

  • Loading branch information...
1 parent fbbbd7e commit ff8524824dd2dd3f276ca094d42ac7d22380991e Charles Jolley committed
Showing with 7 additions and 3 deletions.
  1. +6 −2 lib/index.js
  2. +1 −1 package.json
View
8 lib/index.js
@@ -94,7 +94,7 @@ exports.resourceController = function (name, data, on_change) {
});
},
destroy: function (req, res, id) {
- delete(data[id]);
+ delete data[id];
on_change(id);
res.simpleJson(200, "200 Destroyed");
}
@@ -155,7 +155,11 @@ var server = http.createServer(function (req, res) {
});
req.addListener('end', function () {
if (route.format === 'json') {
- body = JSON.parse(body);
+ try {
+ body = JSON.parse(body);
+ } catch(e) {
+ body = null;
+ }
}
match.push(body);
route.handler.apply(null, match);
View
2 package.json
@@ -2,5 +2,5 @@
"name": "node-router",
"description": "A simple http server for node.js that has sinatra like qualities. Ideal for generating web services via node.",
"author": "creatonix (http://github.com/creationix)",
- "version": "0.1.0"
+ "version": "0.1.1"
}

0 comments on commit ff85248

Please sign in to comment.
Something went wrong with that request. Please try again.