     db.get params.id, (err, doc) =>
         if err and err.error == "not_found"
             app.locker.removeLock @lock
-            deleteFiles req, -> send 404
+            deleteFiles req, -> send error: err.error, 404
         else if err
             console.log "[Attachment] err: " + JSON.stringify err
             app.locker.removeLock @lock
-            deleteFiles req, -> send 500
+            deleteFiles req, -> send error: err.error, 500
         else if doc?
             @doc = doc
             next()
         else
             app.locker.removeLock @lock
-            deleteFiles req, -> send 404
+            deleteFiles req, -> send error: "not found", 404
 
 
 ## Actions

        stream = db.saveAttachment @doc, fileData, (err, res) ->
            if err
                console.log "[Attachment] err: " + JSON.stringify err
                deleteFiles req, -> send 500
            else
                deleteFiles req, -> send 201

        fs.createReadStream(file.path).pipe(stream)



    stream = db.getAttachment @doc.id, name, (err) ->
        if err and err.error = "not_found"
            send error: err.error, 404
        else if err
            send error: err.error, 500
        else
            send 200

