You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2021/07/14 20:15:48 UTC

[GitHub] [couchdb] nickva commented on a change in pull request #3667: Fix response code for nonexistent attachment

nickva commented on a change in pull request #3667:
URL: https://github.com/apache/couchdb/pull/3667#discussion_r669922418



##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -1819,6 +1819,21 @@ db_attachment_req(#httpd{method = Method} = Req, Db, DocId, FileNameParts) when
         )
     ),
 
+    % Check if attachment exists
+    #doc_query_args{
+        rev=Rev,
+        options=Options
+    } = parse_doc_query(Req),
+    #doc{
+        atts=Atts
+    } = Doc = couch_doc_open(Db, DocId, Rev, Options),
+    case [A || A <- Atts, couch_att:fetch(name, A) == FileName] of
+        [] ->
+            throw({not_found, "Document is missing attachment"});

Review comment:
       This should be for `DELETE` only not `PUT`?
   
   I saw the logic for opening the named attachment is similar to the code in `GET` handler, perhaps we can re-use it as `get_attachment(Req, Db, DocID, Rev, FileName) -> {ok,  Att} | {error, missing}` which both GET and DELETE can re-use?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org