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

        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)


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


## Actions
