 action 'remove', ->
     removeIndex = ->
         client.del "index/#{params.id}/", (err, res, resbody) ->
-            if err
-                send 500
+            if err?
+                send error: err.message, 500
             else
-                send {success: true, msg: resbody}, res.statusCode
+                send success: true, 200
         , false # body is not JSON
 
     db.get params.id, (err, doc) ->
-        permission doc.docType, () =>
+        permission doc.docType, ->
             if doc?
-                permission doc.docType, () =>
-                    removeIndex(doc)
+                permission doc.docType, ->
+                    removeIndex doc
             else
-                send 404
+                send err: "not found", 404
 
 
 # DELETE /data/index/clear-all/

action 'removeAll', ->
    client.del "clear-all/", (err, res, resbody) ->
        if err
            send 500
        else
            send {success: true, msg: resbody}, res.statusCode
    , false  # body is not JSON

            fields: body.fields
        client.post "index/", data, (err, res, resbody) ->
            if err or res.statusCode != 200
                send error: JSON.stringify err, 500
            else
                send success: true, 200
        , false # body = indexation succeeds, do not parse

    db.get params.id, (err, doc) ->
