 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/

            permission doc.docType, () =>
                indexDoc(doc)
        else
            send 404


# POST /data/search/


    client.post "search/", data, (err, res, resbody) ->
        if err
            send error: err.message, 500
        else if not res?
            send error: err.message, 500
        else if res.statusCode != 200
            send resbody, res.statusCode
        else
            db.get resbody.ids, (err, docs) ->
                if err
                    send error: err.message, 500
                else
                    results = []
                    for doc in docs
