             unless err
                 # Check doc
                 err = checkPermissions req, doc.docType
-                console.log err
                 if err
+                    # Device isn't authorized
                     res.send 403, err
                     stream.emit 'end'
                     couchReq.end()

    data = []
    permissions = false
    req.on 'data', (chunk) =>
        console.log 'data'
        if permissions
            stream.emit 'data', chunk
        else

    startJson = jsonPart.indexOf '{'
    endJson = jsonPart.lastIndexOf '}'
    json = jsonPart.substring startJson, endJson+1
    return [null, JSON.parse(json)]


