couchbase 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/CMakeLists.txt +3 -0
  4. data/ext/build_version.hxx.in +1 -1
  5. data/ext/cmake/CompilerWarnings.cmake +1 -0
  6. data/ext/cmake/PreventInSourceBuilds.cmake +4 -1
  7. data/ext/couchbase/bucket.hxx +28 -2
  8. data/ext/couchbase/cluster.hxx +8 -2
  9. data/ext/couchbase/couchbase.cxx +955 -511
  10. data/ext/couchbase/error_context/analytics.hxx +46 -0
  11. data/ext/couchbase/error_context/http.hxx +44 -0
  12. data/ext/couchbase/error_context/key_value.hxx +47 -0
  13. data/ext/couchbase/error_context/query.hxx +46 -0
  14. data/ext/couchbase/error_context/search.hxx +47 -0
  15. data/ext/couchbase/error_context/view.hxx +47 -0
  16. data/ext/couchbase/io/dns_codec.hxx +1 -2
  17. data/ext/couchbase/io/http_command.hxx +16 -3
  18. data/ext/couchbase/io/http_context.hxx +1 -1
  19. data/ext/couchbase/io/http_session.hxx +12 -6
  20. data/ext/couchbase/io/http_session_manager.hxx +25 -24
  21. data/ext/couchbase/io/mcbp_session.hxx +8 -2
  22. data/ext/couchbase/io/retry_context.hxx +1 -1
  23. data/ext/couchbase/operations/analytics_dataset_create.hxx +19 -12
  24. data/ext/couchbase/operations/analytics_dataset_drop.hxx +18 -10
  25. data/ext/couchbase/operations/analytics_dataset_get_all.hxx +16 -10
  26. data/ext/couchbase/operations/analytics_dataverse_create.hxx +18 -11
  27. data/ext/couchbase/operations/analytics_dataverse_drop.hxx +17 -11
  28. data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +17 -10
  29. data/ext/couchbase/operations/analytics_index_create.hxx +17 -11
  30. data/ext/couchbase/operations/analytics_index_drop.hxx +16 -10
  31. data/ext/couchbase/operations/analytics_index_get_all.hxx +14 -10
  32. data/ext/couchbase/operations/analytics_link_connect.hxx +15 -9
  33. data/ext/couchbase/operations/analytics_link_disconnect.hxx +16 -10
  34. data/ext/couchbase/operations/bucket_create.hxx +33 -10
  35. data/ext/couchbase/operations/bucket_drop.hxx +9 -8
  36. data/ext/couchbase/operations/bucket_flush.hxx +8 -8
  37. data/ext/couchbase/operations/bucket_get.hxx +15 -10
  38. data/ext/couchbase/operations/bucket_get_all.hxx +14 -7
  39. data/ext/couchbase/operations/bucket_settings.hxx +16 -0
  40. data/ext/couchbase/operations/bucket_update.hxx +32 -10
  41. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +6 -6
  42. data/ext/couchbase/operations/collection_create.hxx +19 -13
  43. data/ext/couchbase/operations/collection_drop.hxx +18 -12
  44. data/ext/couchbase/operations/collections_manifest_get.hxx +5 -10
  45. data/ext/couchbase/operations/document_analytics.hxx +39 -17
  46. data/ext/couchbase/operations/document_append.hxx +5 -10
  47. data/ext/couchbase/operations/document_decrement.hxx +5 -10
  48. data/ext/couchbase/operations/document_exists.hxx +4 -6
  49. data/ext/couchbase/operations/document_get.hxx +6 -10
  50. data/ext/couchbase/operations/document_get_and_lock.hxx +4 -9
  51. data/ext/couchbase/operations/document_get_and_touch.hxx +4 -9
  52. data/ext/couchbase/operations/document_get_projected.hxx +21 -14
  53. data/ext/couchbase/operations/document_increment.hxx +5 -10
  54. data/ext/couchbase/operations/document_insert.hxx +5 -10
  55. data/ext/couchbase/operations/document_lookup_in.hxx +4 -9
  56. data/ext/couchbase/operations/document_mutate_in.hxx +7 -12
  57. data/ext/couchbase/operations/document_prepend.hxx +5 -10
  58. data/ext/couchbase/operations/document_query.hxx +45 -28
  59. data/ext/couchbase/operations/document_remove.hxx +5 -10
  60. data/ext/couchbase/operations/document_replace.hxx +5 -10
  61. data/ext/couchbase/operations/document_search.hxx +37 -16
  62. data/ext/couchbase/operations/document_touch.hxx +4 -9
  63. data/ext/couchbase/operations/document_unlock.hxx +4 -9
  64. data/ext/couchbase/operations/document_upsert.hxx +5 -10
  65. data/ext/couchbase/operations/document_view.hxx +29 -13
  66. data/ext/couchbase/operations/group_drop.hxx +7 -7
  67. data/ext/couchbase/operations/group_get.hxx +14 -10
  68. data/ext/couchbase/operations/group_get_all.hxx +14 -8
  69. data/ext/couchbase/operations/group_upsert.hxx +15 -9
  70. data/ext/couchbase/operations/http_noop.hxx +5 -5
  71. data/ext/couchbase/operations/mcbp_noop.hxx +3 -9
  72. data/ext/couchbase/operations/query_index_build_deferred.hxx +15 -9
  73. data/ext/couchbase/operations/query_index_create.hxx +16 -10
  74. data/ext/couchbase/operations/query_index_drop.hxx +16 -10
  75. data/ext/couchbase/operations/query_index_get_all.hxx +13 -7
  76. data/ext/couchbase/operations/role_get_all.hxx +14 -8
  77. data/ext/couchbase/operations/scope_create.hxx +19 -13
  78. data/ext/couchbase/operations/scope_drop.hxx +17 -11
  79. data/ext/couchbase/operations/scope_get_all.hxx +15 -10
  80. data/ext/couchbase/operations/search_get_stats.hxx +5 -5
  81. data/ext/couchbase/operations/search_index_analyze_document.hxx +25 -13
  82. data/ext/couchbase/operations/search_index_control_ingest.hxx +23 -11
  83. data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +23 -11
  84. data/ext/couchbase/operations/search_index_control_query.hxx +23 -11
  85. data/ext/couchbase/operations/search_index_drop.hxx +22 -10
  86. data/ext/couchbase/operations/search_index_get.hxx +22 -10
  87. data/ext/couchbase/operations/search_index_get_all.hxx +13 -7
  88. data/ext/couchbase/operations/search_index_get_documents_count.hxx +24 -13
  89. data/ext/couchbase/operations/search_index_get_stats.hxx +16 -10
  90. data/ext/couchbase/operations/search_index_upsert.hxx +23 -11
  91. data/ext/couchbase/operations/user_drop.hxx +8 -8
  92. data/ext/couchbase/operations/user_get.hxx +14 -10
  93. data/ext/couchbase/operations/user_get_all.hxx +14 -8
  94. data/ext/couchbase/operations/user_upsert.hxx +15 -9
  95. data/ext/couchbase/operations/view_index_drop.hxx +7 -7
  96. data/ext/couchbase/operations/view_index_get.hxx +15 -9
  97. data/ext/couchbase/operations/view_index_get_all.hxx +15 -9
  98. data/ext/couchbase/operations/view_index_upsert.hxx +8 -8
  99. data/ext/couchbase/origin.hxx +1 -0
  100. data/ext/couchbase/platform/terminate_handler.cc +12 -8
  101. data/ext/couchbase/protocol/client_request.hxx +2 -1
  102. data/ext/couchbase/protocol/client_response.hxx +18 -15
  103. data/ext/couchbase/protocol/cmd_exists.hxx +1 -0
  104. data/ext/couchbase/protocol/cmd_get.hxx +1 -1
  105. data/ext/couchbase/protocol/cmd_mutate_in.hxx +3 -4
  106. data/ext/couchbase/protocol/enhanced_error_info.hxx +28 -0
  107. data/ext/couchbase/utils/connection_string.hxx +1 -1
  108. data/ext/couchbase/version.hxx +1 -1
  109. data/ext/extconf.rb +1 -1
  110. data/ext/test/test_native_binary_operations.cxx +18 -18
  111. data/ext/test/test_native_diagnostics.cxx +2 -2
  112. data/ext/test/test_native_trivial_crud.cxx +2 -2
  113. data/ext/third_party/json/include/tao/json/external/pegtl/internal/file_reader.hpp +1 -5
  114. data/lib/active_support/cache/couchbase_store.rb +362 -0
  115. data/lib/couchbase.rb +2 -0
  116. data/lib/couchbase/authenticator.rb +26 -0
  117. data/lib/couchbase/binary_collection.rb +1 -0
  118. data/lib/couchbase/bucket.rb +1 -0
  119. data/lib/couchbase/cluster.rb +51 -27
  120. data/lib/couchbase/collection.rb +19 -4
  121. data/lib/couchbase/collection_options.rb +10 -0
  122. data/lib/couchbase/configuration.rb +57 -0
  123. data/lib/couchbase/datastructures.rb +6 -0
  124. data/lib/couchbase/errors.rb +111 -3
  125. data/lib/couchbase/management.rb +27 -0
  126. data/lib/couchbase/management/bucket_manager.rb +9 -2
  127. data/lib/couchbase/management/collection_manager.rb +1 -1
  128. data/lib/couchbase/management/user_manager.rb +18 -2
  129. data/lib/couchbase/options.rb +33 -23
  130. data/lib/couchbase/railtie.rb +45 -0
  131. data/lib/couchbase/scope.rb +44 -3
  132. data/lib/couchbase/utils.rb +21 -0
  133. data/lib/couchbase/utils/time.rb +52 -0
  134. data/lib/couchbase/version.rb +1 -1
  135. data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
  136. metadata +19 -5
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -27,8 +27,7 @@ namespace couchbase::operations
27
27
  {
28
28
 
29
29
  struct group_get_all_response {
30
- std::string client_context_id;
31
- std::error_code ec;
30
+ error_context::http ctx;
32
31
  std::vector<rbac::group> groups{};
33
32
  };
34
33
 
@@ -36,6 +35,7 @@ struct group_get_all_request {
36
35
  using response_type = group_get_all_response;
37
36
  using encoded_request_type = io::http_request;
38
37
  using encoded_response_type = io::http_response;
38
+ using error_context_type = error_context::http;
39
39
 
40
40
  static const inline service_type type = service_type::management;
41
41
 
@@ -52,17 +52,23 @@ struct group_get_all_request {
52
52
  };
53
53
 
54
54
  group_get_all_response
55
- make_response(std::error_code ec, group_get_all_request& request, group_get_all_request::encoded_response_type&& encoded)
55
+ make_response(error_context::http&& ctx, group_get_all_request&, group_get_all_request::encoded_response_type&& encoded)
56
56
  {
57
- group_get_all_response response{ request.client_context_id, ec };
58
- if (!ec) {
57
+ group_get_all_response response{ ctx };
58
+ if (!response.ctx.ec) {
59
59
  if (encoded.status_code == 200) {
60
- tao::json::value payload = tao::json::from_string(encoded.body);
60
+ tao::json::value payload{};
61
+ try {
62
+ payload = tao::json::from_string(encoded.body);
63
+ } catch (tao::json::pegtl::parse_error& e) {
64
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
65
+ return response;
66
+ }
61
67
  for (const auto& entry : payload.get_array()) {
62
68
  response.groups.emplace_back(entry.as<rbac::group>());
63
69
  }
64
70
  } else {
65
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
71
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
66
72
  }
67
73
  }
68
74
  return response;
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -31,8 +31,7 @@ namespace couchbase::operations
31
31
  {
32
32
 
33
33
  struct group_upsert_response {
34
- std::string client_context_id;
35
- std::error_code ec;
34
+ error_context::http ctx;
36
35
  std::vector<std::string> errors{};
37
36
  };
38
37
 
@@ -40,6 +39,7 @@ struct group_upsert_request {
40
39
  using response_type = group_upsert_response;
41
40
  using encoded_request_type = io::http_request;
42
41
  using encoded_response_type = io::http_response;
42
+ using error_context_type = error_context::http;
43
43
 
44
44
  static const inline service_type type = service_type::management;
45
45
 
@@ -91,16 +91,22 @@ struct group_upsert_request {
91
91
  };
92
92
 
93
93
  group_upsert_response
94
- make_response(std::error_code ec, group_upsert_request& request, group_upsert_request::encoded_response_type&& encoded)
94
+ make_response(error_context::http&& ctx, group_upsert_request&, group_upsert_request::encoded_response_type&& encoded)
95
95
  {
96
- group_upsert_response response{ request.client_context_id, ec };
97
- if (!ec) {
96
+ group_upsert_response response{ ctx };
97
+ if (!response.ctx.ec) {
98
98
  switch (encoded.status_code) {
99
99
  case 200:
100
100
  break;
101
101
  case 400: {
102
- response.ec = std::make_error_code(error::common_errc::invalid_argument);
103
- tao::json::value payload = tao::json::from_string(encoded.body);
102
+ response.ctx.ec = std::make_error_code(error::common_errc::invalid_argument);
103
+ tao::json::value payload{};
104
+ try {
105
+ payload = tao::json::from_string(encoded.body);
106
+ } catch (tao::json::pegtl::parse_error& e) {
107
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
108
+ return response;
109
+ }
104
110
  const auto* errors = payload.find("errors");
105
111
  if (errors != nullptr && errors->is_object()) {
106
112
  for (const auto& entry : errors->get_object()) {
@@ -109,7 +115,7 @@ make_response(std::error_code ec, group_upsert_request& request, group_upsert_re
109
115
  }
110
116
  } break;
111
117
  default:
112
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
118
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
113
119
  break;
114
120
  }
115
121
  }
@@ -20,19 +20,19 @@
20
20
  #include <tao/json.hpp>
21
21
 
22
22
  #include <version.hxx>
23
+ #include <error_context/http.hxx>
23
24
 
24
25
  namespace couchbase::operations
25
26
  {
26
27
  struct http_noop_response {
27
- std::string client_context_id;
28
- std::error_code ec;
29
- uint32_t status_code;
28
+ error_context::http ctx;
30
29
  };
31
30
 
32
31
  struct http_noop_request {
33
32
  using response_type = http_noop_response;
34
33
  using encoded_request_type = io::http_request;
35
34
  using encoded_response_type = io::http_response;
35
+ using error_context_type = error_context::http;
36
36
 
37
37
  service_type type;
38
38
  std::chrono::milliseconds timeout;
@@ -69,9 +69,9 @@ struct http_noop_request {
69
69
  };
70
70
 
71
71
  http_noop_response
72
- make_response(std::error_code ec, http_noop_request& request, http_noop_request::encoded_response_type&& encoded)
72
+ make_response(error_context::http&& ctx, http_noop_request&, http_noop_request::encoded_response_type&&)
73
73
  {
74
- http_noop_response response{ request.client_context_id, ec, encoded.status_code };
74
+ http_noop_response response{ ctx };
75
75
  return response;
76
76
  }
77
77
 
@@ -25,10 +25,7 @@ namespace couchbase::operations
25
25
  {
26
26
 
27
27
  struct mcbp_noop_response {
28
- std::uint32_t opaque;
29
- std::error_code ec{};
30
- std::chrono::steady_clock::time_point start{};
31
- std::chrono::steady_clock::time_point stop{};
28
+ error_context::key_value ctx;
32
29
  };
33
30
 
34
31
  struct mcbp_noop_request {
@@ -49,12 +46,9 @@ struct mcbp_noop_request {
49
46
  };
50
47
 
51
48
  mcbp_noop_response
52
- make_response(std::error_code ec, mcbp_noop_request& request, mcbp_noop_request::encoded_response_type&& encoded)
49
+ make_response(error_context::key_value&& ctx, mcbp_noop_request&, mcbp_noop_request::encoded_response_type&&)
53
50
  {
54
- mcbp_noop_response response{ encoded.opaque(), ec };
55
- if (ec && response.opaque == 0) {
56
- response.opaque = request.opaque;
57
- }
51
+ mcbp_noop_response response{ ctx };
58
52
  return response;
59
53
  }
60
54
 
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -28,8 +28,7 @@ struct query_index_build_deferred_response {
28
28
  std::uint64_t code;
29
29
  std::string message;
30
30
  };
31
- std::string client_context_id;
32
- std::error_code ec;
31
+ error_context::http ctx;
33
32
  std::string status{};
34
33
  std::vector<query_problem> errors{};
35
34
  };
@@ -38,6 +37,7 @@ struct query_index_build_deferred_request {
38
37
  using response_type = query_index_build_deferred_response;
39
38
  using encoded_request_type = io::http_request;
40
39
  using encoded_response_type = io::http_response;
40
+ using error_context_type = error_context::http;
41
41
 
42
42
  static const inline service_type type = service_type::query;
43
43
 
@@ -63,13 +63,19 @@ struct query_index_build_deferred_request {
63
63
  };
64
64
 
65
65
  query_index_build_deferred_response
66
- make_response(std::error_code ec,
67
- query_index_build_deferred_request& request,
66
+ make_response(error_context::http&& ctx,
67
+ query_index_build_deferred_request&,
68
68
  query_index_build_deferred_request::encoded_response_type&& encoded)
69
69
  {
70
- query_index_build_deferred_response response{ request.client_context_id, ec };
71
- if (!ec) {
72
- auto payload = tao::json::from_string(encoded.body);
70
+ query_index_build_deferred_response response{ ctx };
71
+ if (!response.ctx.ec) {
72
+ tao::json::value payload{};
73
+ try {
74
+ payload = tao::json::from_string(encoded.body);
75
+ } catch (tao::json::pegtl::parse_error& e) {
76
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
77
+ return response;
78
+ }
73
79
  response.status = payload.at("status").get_string();
74
80
  if (response.status != "success") {
75
81
  for (const auto& entry : payload.at("errors").get_array()) {
@@ -78,7 +84,7 @@ make_response(std::error_code ec,
78
84
  error.message = entry.at("msg").get_string();
79
85
  response.errors.emplace_back(error);
80
86
  }
81
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
87
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
82
88
  }
83
89
  }
84
90
  return response;
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -28,8 +28,7 @@ struct query_index_create_response {
28
28
  std::uint64_t code;
29
29
  std::string message;
30
30
  };
31
- std::string client_context_id;
32
- std::error_code ec;
31
+ error_context::http ctx;
33
32
  std::string status{};
34
33
  std::vector<query_problem> errors{};
35
34
  };
@@ -38,6 +37,7 @@ struct query_index_create_request {
38
37
  using response_type = query_index_create_response;
39
38
  using encoded_request_type = io::http_request;
40
39
  using encoded_response_type = io::http_response;
40
+ using error_context_type = error_context::http;
41
41
 
42
42
  static const inline service_type type = service_type::query;
43
43
 
@@ -100,11 +100,17 @@ struct query_index_create_request {
100
100
  };
101
101
 
102
102
  query_index_create_response
103
- make_response(std::error_code ec, query_index_create_request& request, query_index_create_request::encoded_response_type&& encoded)
103
+ make_response(error_context::http&& ctx, query_index_create_request& request, query_index_create_request::encoded_response_type&& encoded)
104
104
  {
105
- query_index_create_response response{ request.client_context_id, ec };
106
- if (!ec) {
107
- auto payload = tao::json::from_string(encoded.body);
105
+ query_index_create_response response{ ctx };
106
+ if (!response.ctx.ec) {
107
+ tao::json::value payload{};
108
+ try {
109
+ payload = tao::json::from_string(encoded.body);
110
+ } catch (tao::json::pegtl::parse_error& e) {
111
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
112
+ return response;
113
+ }
108
114
  response.status = payload.at("status").get_string();
109
115
 
110
116
  if (response.status != "success") {
@@ -131,12 +137,12 @@ make_response(std::error_code ec, query_index_create_request& request, query_ind
131
137
  }
132
138
  if (index_already_exists) {
133
139
  if (!request.ignore_if_exists) {
134
- response.ec = std::make_error_code(error::common_errc::index_exists);
140
+ response.ctx.ec = std::make_error_code(error::common_errc::index_exists);
135
141
  }
136
142
  } else if (bucket_not_found) {
137
- response.ec = std::make_error_code(error::common_errc::bucket_not_found);
143
+ response.ctx.ec = std::make_error_code(error::common_errc::bucket_not_found);
138
144
  } else if (!response.errors.empty()) {
139
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
145
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
140
146
  }
141
147
  }
142
148
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -28,8 +28,7 @@ struct query_index_drop_response {
28
28
  std::uint64_t code;
29
29
  std::string message;
30
30
  };
31
- std::string client_context_id;
32
- std::error_code ec;
31
+ error_context::http ctx;
33
32
  std::string status{};
34
33
  std::vector<query_problem> errors{};
35
34
  };
@@ -38,6 +37,7 @@ struct query_index_drop_request {
38
37
  using response_type = query_index_drop_response;
39
38
  using encoded_request_type = io::http_request;
40
39
  using encoded_response_type = io::http_response;
40
+ using error_context_type = error_context::http;
41
41
 
42
42
  static const inline service_type type = service_type::query;
43
43
 
@@ -73,11 +73,17 @@ struct query_index_drop_request {
73
73
  };
74
74
 
75
75
  query_index_drop_response
76
- make_response(std::error_code ec, query_index_drop_request& request, query_index_drop_request::encoded_response_type&& encoded)
76
+ make_response(error_context::http&& ctx, query_index_drop_request& request, query_index_drop_request::encoded_response_type&& encoded)
77
77
  {
78
- query_index_drop_response response{ request.client_context_id, ec };
79
- if (!ec) {
80
- auto payload = tao::json::from_string(encoded.body);
78
+ query_index_drop_response response{ ctx };
79
+ if (!response.ctx.ec) {
80
+ tao::json::value payload{};
81
+ try {
82
+ payload = tao::json::from_string(encoded.body);
83
+ } catch (tao::json::pegtl::parse_error& e) {
84
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
85
+ return response;
86
+ }
81
87
  response.status = payload.at("status").get_string();
82
88
 
83
89
  if (response.status != "success") {
@@ -105,12 +111,12 @@ make_response(std::error_code ec, query_index_drop_request& request, query_index
105
111
  }
106
112
  if (index_not_found) {
107
113
  if (!request.ignore_if_does_not_exist) {
108
- response.ec = std::make_error_code(error::common_errc::index_not_found);
114
+ response.ctx.ec = std::make_error_code(error::common_errc::index_not_found);
109
115
  }
110
116
  } else if (bucket_not_found) {
111
- response.ec = std::make_error_code(error::common_errc::bucket_not_found);
117
+ response.ctx.ec = std::make_error_code(error::common_errc::bucket_not_found);
112
118
  } else if (!response.errors.empty()) {
113
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
119
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
114
120
  }
115
121
  }
116
122
  }
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -39,8 +39,7 @@ struct query_index_get_all_response {
39
39
  std::optional<std::string> bucket_id{};
40
40
  std::optional<std::string> scope_id{};
41
41
  };
42
- std::string client_context_id;
43
- std::error_code ec;
42
+ error_context::http ctx;
44
43
  std::string status{};
45
44
  std::vector<query_index> indexes{};
46
45
  };
@@ -49,6 +48,7 @@ struct query_index_get_all_request {
49
48
  using response_type = query_index_get_all_response;
50
49
  using encoded_request_type = io::http_request;
51
50
  using encoded_response_type = io::http_response;
51
+ using error_context_type = error_context::http;
52
52
 
53
53
  static const inline service_type type = service_type::query;
54
54
 
@@ -75,12 +75,18 @@ struct query_index_get_all_request {
75
75
  };
76
76
 
77
77
  query_index_get_all_response
78
- make_response(std::error_code ec, query_index_get_all_request& request, query_index_get_all_request::encoded_response_type&& encoded)
78
+ make_response(error_context::http&& ctx, query_index_get_all_request&, query_index_get_all_request::encoded_response_type&& encoded)
79
79
  {
80
- query_index_get_all_response response{ request.client_context_id, ec };
81
- if (!ec) {
80
+ query_index_get_all_response response{ ctx };
81
+ if (!response.ctx.ec) {
82
82
  if (encoded.status_code == 200) {
83
- auto payload = tao::json::from_string(encoded.body);
83
+ tao::json::value payload{};
84
+ try {
85
+ payload = tao::json::from_string(encoded.body);
86
+ } catch (tao::json::pegtl::parse_error& e) {
87
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
88
+ return response;
89
+ }
84
90
  response.status = payload.at("status").get_string();
85
91
  if (response.status == "success") {
86
92
  for (const auto& entry : payload.at("results").get_array()) {
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -27,8 +27,7 @@ namespace couchbase::operations
27
27
  {
28
28
 
29
29
  struct role_get_all_response {
30
- std::string client_context_id;
31
- std::error_code ec;
30
+ error_context::http ctx;
32
31
  std::vector<rbac::role_and_description> roles{};
33
32
  };
34
33
 
@@ -36,6 +35,7 @@ struct role_get_all_request {
36
35
  using response_type = role_get_all_response;
37
36
  using encoded_request_type = io::http_request;
38
37
  using encoded_response_type = io::http_response;
38
+ using error_context_type = error_context::http;
39
39
 
40
40
  static const inline service_type type = service_type::management;
41
41
 
@@ -52,17 +52,23 @@ struct role_get_all_request {
52
52
  };
53
53
 
54
54
  role_get_all_response
55
- make_response(std::error_code ec, role_get_all_request& request, role_get_all_request::encoded_response_type&& encoded)
55
+ make_response(error_context::http&& ctx, role_get_all_request&, role_get_all_request::encoded_response_type&& encoded)
56
56
  {
57
- role_get_all_response response{ request.client_context_id, ec };
58
- if (!ec) {
57
+ role_get_all_response response{ ctx };
58
+ if (!response.ctx.ec) {
59
59
  if (encoded.status_code == 200) {
60
- tao::json::value payload = tao::json::from_string(encoded.body);
60
+ tao::json::value payload{};
61
+ try {
62
+ payload = tao::json::from_string(encoded.body);
63
+ } catch (tao::json::pegtl::parse_error& e) {
64
+ response.ctx.ec = std::make_error_code(error::common_errc::parsing_failure);
65
+ return response;
66
+ }
61
67
  for (const auto& entry : payload.get_array()) {
62
68
  response.roles.emplace_back(entry.as<rbac::role_and_description>());
63
69
  }
64
70
  } else {
65
- response.ec = std::make_error_code(error::common_errc::internal_server_failure);
71
+ response.ctx.ec = std::make_error_code(error::common_errc::internal_server_failure);
66
72
  }
67
73
  }
68
74
  return response;