diff options
author | Jay Doane <jay.s.doane@gmail.com> | 2017-06-15 22:12:13 -0700 |
---|---|---|
committer | Nick Vatamaniuc <nickva@users.noreply.github.com> | 2017-06-16 01:59:06 -0400 |
commit | d3bae3f14062b6957f5daaa7208c4b7ed63154ac (patch) | |
tree | 972431454c18debec05913fa44ac6d202847d5c0 | |
parent | 2269b644770a9a53d4571ced8a9e996c95d30979 (diff) | |
download | couchdb-d3bae3f14062b6957f5daaa7208c4b7ed63154ac.tar.gz |
Return 409 to PUT attachment with non-existent rev
Currently we return a 500 and something like
{"error":"{not_found,missing}","reason":"{1,<<\"000\">>}"}
when an attempt is made to put an attachment document with a
non-existent revision.
This changes the behavior to return a 409 and
{"error":"not_found","reason":"missing_rev"}"
-rw-r--r-- | src/chttpd/src/chttpd.erl | 2 | ||||
-rw-r--r-- | src/chttpd/test/chttpd_db_test.erl | 18 | ||||
-rw-r--r-- | test/javascript/tests/attachments.js | 3 |
3 files changed, 20 insertions, 3 deletions
diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl index 76eb7c37b..86c2752c1 100644 --- a/src/chttpd/src/chttpd.erl +++ b/src/chttpd/src/chttpd.erl @@ -850,6 +850,8 @@ error_info(conflict) -> {409, <<"conflict">>, <<"Document update conflict.">>}; error_info({conflict, _}) -> {409, <<"conflict">>, <<"Document update conflict.">>}; +error_info({{not_found, missing}, {_, _}}) -> + {409, <<"not_found">>, <<"missing_rev">>}; error_info({forbidden, Error, Msg}) -> {403, Error, Msg}; error_info({forbidden, Msg}) -> diff --git a/src/chttpd/test/chttpd_db_test.erl b/src/chttpd/test/chttpd_db_test.erl index 0ff415bd0..f3c779bd3 100644 --- a/src/chttpd/test/chttpd_db_test.erl +++ b/src/chttpd/test/chttpd_db_test.erl @@ -61,7 +61,8 @@ all_test_() -> fun should_accept_live_as_an_alias_for_continuous/1, fun should_return_404_for_delete_att_on_notadoc/1, fun should_return_409_for_del_att_without_rev/1, - fun should_return_200_for_del_att_with_rev/1 + fun should_return_200_for_del_att_with_rev/1, + fun should_return_409_for_put_att_nonexistent_rev/1 ] } } @@ -171,6 +172,21 @@ should_return_200_for_del_att_with_rev(Url) -> end). +should_return_409_for_put_att_nonexistent_rev(Url) -> + ?_test(begin + {ok, RC, _Headers, RespBody} = test_request:put( + Url ++ "/should_return_404/file.erl?rev=1-000", + [?CONTENT_JSON, ?AUTH], + jiffy:encode(attachment_doc()) + ), + ?assertEqual(409, RC), + ?assertMatch({[ + {<<"error">>,<<"not_found">>}, + {<<"reason">>,<<"missing_rev">>}]}, + ?JSON_DECODE(RespBody)) + end). + + attachment_doc() -> {ok, Data} = file:read_file(?FIXTURE_TXT), {[ diff --git a/test/javascript/tests/attachments.js b/test/javascript/tests/attachments.js index b40096c7d..cd6474d0f 100644 --- a/test/javascript/tests/attachments.js +++ b/test/javascript/tests/attachments.js @@ -116,8 +116,7 @@ couchTests.attachments= function(debug) { headers:{"Content-Type":"text/plain;charset=utf-8"}, body:bin_data }); -// TODO: revisit whether 500 makes sense for non-existing revs - T(xhr.status == 409 || xhr.status == 500); + T(xhr.status == 409); // with current rev var xhr = CouchDB.request("PUT", "/" + db_name + "/bin_doc3/attachment.txt?rev=" + rev, { |