maxogden/datacouch — Issue #28: Taco de pulpo
Author: bvmou
Created: 2012-01-30 07:47:48+00:00
State: open

I think there is a spot in dataset update from paste api where json is being parsed more than once, leading to the below error:

```
[2012-01-29 23:01:06.771] [INFO] console - [request] POST http://bvm:******@localhost:5983/dcd667629546bef4b657d5275993013357/_ensure_full_commit

undefined:1
s����	�M
^
SyntaxError: Unexpected token '
at Object.parse (native)
at IncomingMessage. (/home/bvm/prg/lang/js/datacouch/node_modules/tako/index.js:423:33)
at IncomingMessage. (events.js:88:20)
at IncomingMessage. (/home/bvm/prg/lang/js/datacouch/node_modules/tako/index.js:303:13)
at IncomingMessage. (events.js:88:20)
at HTTPParser.onMessageComplete (http.js:137:23)
at Socket.ondata (http.js:1387:22)
at TCP.onread (net.js:354:27)
bvm@bvm:~/prg/lang/js/datacouch$ node run.js
```

Tako index.js after line 420 will quieten with the below, but this feels inconsistent with the rest of the module, like casting to pointer void twice to shut up a compiler, but I just sort of add here in case it is more obvious what unexpected things might be happening, or what should be provisioned beforehand in these cases (ie, starting out a dataset with a paste)

```
if (req.method === "PUT" || req.method === "POST") {
if (req.headers['content-type'] === 'application/json') {
req.on('body', function (body) {
try {
req.emit('json', JSON.parse(body))
} catch (e) {
try {
req.emit('json', body)
} catch (f) {
throw "wasnt too parsed"
}
}
})
}
}
```