Skip to content

Commit a94d88d

Browse files
authored
CXXCBC-374: create_bucket does not return a BucketExists error when a duplicate bucket is created (#449)
* Add check for status code 400 and bucket exists message * add test * Add history feature not avaialble to bucket create and update * linting * undo history retention change
1 parent 9c07f43 commit a94d88d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

core/operations/management/bucket_create.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ bucket_create_request::make_response(error_context::http&& ctx, const encoded_re
161161
if (errors != nullptr) {
162162
std::vector<std::string> error_list{};
163163
for (const auto& [code, message] : errors->get_object()) {
164+
if (message.get_string().find("Bucket with given name already exists") != std::string::npos) {
165+
response.ctx.ec = errc::management::bucket_exists;
166+
}
164167
error_list.emplace_back(message.get_string());
165168
}
166169
if (!error_list.empty()) {

test/test_integration_management.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ TEST_CASE("integration: bucket management", "[integration]")
109109
REQUIRE(bucket_settings.compression_mode == resp.bucket.compression_mode);
110110
REQUIRE(bucket_settings.replica_indexes == resp.bucket.replica_indexes);
111111
}
112+
113+
{
114+
couchbase::core::operations::management::bucket_create_request req;
115+
req.bucket = bucket_settings;
116+
auto resp = test::utils::execute(integration.cluster, req);
117+
REQUIRE(resp.ctx.ec == couchbase::errc::management::bucket_exists);
118+
}
119+
112120
std::uint64_t old_quota_mb{ 0 };
113121
{
114122
couchbase::core::operations::management::bucket_get_all_request req{};

0 commit comments

Comments
 (0)