From 649b8ac55380d68ca4acec4173a512825854ad04 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 26 Apr 2011 10:52:27 +0200 Subject: parse: do not crash on unknown url (favicon.ico) --- src/nodejs/main.js | 68 +++++++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/nodejs/main.js b/src/nodejs/main.js index 5006dbc..eed7fda 100644 --- a/src/nodejs/main.js +++ b/src/nodejs/main.js @@ -271,43 +271,47 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) { function myFunction(req,res){ - + // FIXIT: if send head with 200, the following endWith500() call has no effect res.writeHead(200); - var reqObj = parser.urlToXpathObj(req.url); - - var queryDict = buildMainQuery(reqObj); - - var resXml = osmRes.mkXmlRes(res); + try { + var reqObj = parser.urlToXpathObj(req.url); + var queryDict = buildMainQuery(reqObj); + var resXml = osmRes.mkXmlRes(res); + log.debug(JSON.stringify(queryDict)); + log.debug(JSON.stringify(reqObj)); + dbConnect(resXml, function(client) { + var success = false; + var query = client.query(queryDict); - console.log(JSON.stringify(queryDict)); - console.log("??????????????????????????????"); - console.log(JSON.stringify(reqObj)); - dbConnect(resXml, function(client) { - var success = false; - var query = client.query(queryDict); - - query.on('error', function(err) { - res.endWith500(); - }); + query.on('error', function(err) { + log.error(err.message); + res.endWith500(); + }); - query.on('end', function() { - console.log(" EEEND "); - res.atEnd(); - }); - - query.on('row', function(row) { - //console.log(JSON.stringify(row)); - if(reqObj.object == "node") { - var pojo = rowToNode(row); - res.putNode(pojo); - } - else if(reqObj.object == "way") { - var pojo = rowToWay(row); - res.putWay(pojo);} - }); - }); + query.on('end', function() { + log.trace('end'); + res.atEnd(); + }); + + query.on('row', function(row) { + log.trace('next row'); + log.debug(JSON.stringify(row)); + + if(reqObj.object == "node") { + var pojo = rowToNode(row); + res.putNode(pojo); + } + else if(reqObj.object == "way") { + var pojo = rowToWay(row); + res.putWay(pojo);} + }); + }); + } + catch (err) { + log.error(err); + } } function getConfig(configPath, callback) { -- cgit v1.2.3