diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2011-04-26 10:52:27 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2011-04-26 10:52:27 +0200 |
commit | 649b8ac55380d68ca4acec4173a512825854ad04 (patch) | |
tree | 1951204b3a28077798d026d840132c585793f929 | |
parent | 4ce0a2a37f233b9e0b2631266732e40faa0e8297 (diff) | |
download | osm-xapi-649b8ac55380d68ca4acec4173a512825854ad04.tar.gz osm-xapi-649b8ac55380d68ca4acec4173a512825854ad04.tar.xz osm-xapi-649b8ac55380d68ca4acec4173a512825854ad04.zip |
parse: do not crash on unknown url (favicon.ico)
-rw-r--r-- | src/nodejs/main.js | 68 |
1 files 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) { |