@@ -92,39 +92,6 @@ int resolveDestination(DestinationId const& dest, std::string& endpoint) {
92
92
return TRI_ERROR_NO_ERROR;
93
93
}
94
94
95
- OperationResult opResultFromBody (arangodb::velocypack::Buffer<uint8_t > const & body,
96
- int defaultErrorCode) {
97
- if (body.size () > 0 ) {
98
- return opResultFromBody (VPackSlice (body.data ()), defaultErrorCode);
99
- }
100
- return OperationResult (defaultErrorCode);
101
- }
102
-
103
- OperationResult opResultFromBody (std::shared_ptr<VPackBuilder> const & body, int defaultErrorCode) {
104
- if (body) {
105
- return opResultFromBody (body->slice (), defaultErrorCode);
106
- }
107
- return OperationResult (defaultErrorCode);
108
- }
109
-
110
- OperationResult opResultFromBody (VPackSlice body, int defaultErrorCode) {
111
- // read the error number from the response and use it if present
112
- if (body.isObject ()) {
113
- VPackSlice num = body.get (StaticStrings::ErrorNum);
114
- VPackSlice msg = body.get (StaticStrings::ErrorMessage);
115
- if (num.isNumber ()) {
116
- if (msg.isString ()) {
117
- // found an error number and an error message, so let's use it!
118
- return OperationResult (Result (num.getNumericValue <int >(), msg.copyString ()));
119
- }
120
- // we found an error number, so let's use it!
121
- return OperationResult (num.getNumericValue <int >());
122
- }
123
- }
124
-
125
- return OperationResult (defaultErrorCode);
126
- }
127
-
128
95
// / @brief extract the error code form the body
129
96
int errorCodeFromBody (arangodb::velocypack::Slice body) {
130
97
if (body.isObject ()) {
@@ -137,6 +104,15 @@ int errorCodeFromBody(arangodb::velocypack::Slice body) {
137
104
return TRI_ERROR_ILLEGAL_NUMBER;
138
105
}
139
106
107
+ Result resultFromBody (std::shared_ptr<arangodb::velocypack::Buffer<uint8_t >> const & body,
108
+ int defaultError) {
109
+ // read the error number from the response and use it if present
110
+ if (body && !body->empty ()) {
111
+ return resultFromBody (VPackSlice (body->data ()), defaultError);
112
+ }
113
+ return Result (defaultError);
114
+ }
115
+
140
116
Result resultFromBody (std::shared_ptr<arangodb::velocypack::Builder> const & body,
141
117
int defaultError) {
142
118
@@ -191,8 +167,13 @@ void errorCodesFromHeaders(network::Headers headers,
191
167
}
192
168
}
193
169
}
194
-
170
+
195
171
int fuerteToArangoErrorCode (network::Response const & res) {
172
+ return fuerteToArangoErrorCode (res.error );
173
+ }
174
+
175
+ int fuerteToArangoErrorCode (fuerte::Error err) {
176
+
196
177
// This function creates an error code from a ClusterCommResult,
197
178
// but only if it is a communication error. If the communication
198
179
// was successful and there was an HTTP error code, this function
@@ -201,8 +182,9 @@ int fuerteToArangoErrorCode(network::Response const& res) {
201
182
// and .answer can safely be inspected.
202
183
203
184
204
- LOG_TOPIC_IF (" abcde" , ERR, Logger::CLUSTER, res.error != fuerte::Error::NoError) << fuerte::to_string (res.error );
205
- switch (res.error ) {
185
+ // LOG_TOPIC_IF("abcde", ERR, Logger::CLUSTER, res.error != fuerte::Error::NoError) << fuerte::to_string(res.error);
186
+
187
+ switch (err) {
206
188
case fuerte::Error::NoError:
207
189
return TRI_ERROR_NO_ERROR;
208
190
@@ -234,23 +216,23 @@ OperationResult clusterResultInsert(arangodb::fuerte::StatusCode code,
234
216
std::unordered_map<int , size_t > const & errorCounter) {
235
217
switch (code) {
236
218
case fuerte::StatusAccepted:
237
- return OperationResult (Result (), std::move (body), nullptr , options, errorCounter);
219
+ return OperationResult (Result (), std::move (body), options, errorCounter);
238
220
case fuerte::StatusCreated: {
239
221
OperationOptions copy = options;
240
222
copy.waitForSync = true ; // wait for sync is abused herea
241
223
// operationResult should get a return code.
242
- return OperationResult (Result (), std::move (body), nullptr , copy, errorCounter);
224
+ return OperationResult (Result (), std::move (body), copy, errorCounter);
243
225
}
244
226
case fuerte::StatusPreconditionFailed:
245
- return network::opResultFromBody (* body, TRI_ERROR_ARANGO_CONFLICT);
227
+ return network::opResultFromBody (body, TRI_ERROR_ARANGO_CONFLICT);
246
228
case fuerte::StatusBadRequest:
247
- return network::opResultFromBody (* body, TRI_ERROR_INTERNAL);
229
+ return network::opResultFromBody (body, TRI_ERROR_INTERNAL);
248
230
case fuerte::StatusNotFound:
249
- return network::opResultFromBody (* body, TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
231
+ return network::opResultFromBody (body, TRI_ERROR_ARANGO_DATA_SOURCE_NOT_FOUND);
250
232
case fuerte::StatusConflict:
251
- return network::opResultFromBody (* body, TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED);
233
+ return network::opResultFromBody (body, TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED);
252
234
default :
253
- return network::opResultFromBody (* body, TRI_ERROR_INTERNAL);
235
+ return network::opResultFromBody (body, TRI_ERROR_INTERNAL);
254
236
}
255
237
}
256
238
@@ -261,14 +243,40 @@ OperationResult clusterResultDocument(arangodb::fuerte::StatusCode code,
261
243
std::unordered_map<int , size_t > const & errorCounter) {
262
244
switch (code) {
263
245
case fuerte::StatusOK:
264
- return OperationResult (Result (), std::move (body), nullptr , options, errorCounter);
246
+ return OperationResult (Result (), std::move (body), options, errorCounter);
265
247
case fuerte::StatusPreconditionFailed:
266
248
return OperationResult (Result (TRI_ERROR_ARANGO_CONFLICT), std::move (body),
267
- nullptr , options, errorCounter);
249
+ options, errorCounter);
268
250
case fuerte::StatusNotFound:
269
- return network::opResultFromBody (* body, TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND);
251
+ return network::opResultFromBody (body, TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND);
270
252
default :
271
- return network::opResultFromBody (*body, TRI_ERROR_INTERNAL);
253
+ return network::opResultFromBody (body, TRI_ERROR_INTERNAL);
254
+ }
255
+ }
256
+
257
+ // / @brief Create Cluster Communication result for modify
258
+ OperationResult clusterResultModify (arangodb::fuerte::StatusCode code,
259
+ std::shared_ptr<VPackBuffer<uint8_t >> body,
260
+ OperationOptions const & options,
261
+ std::unordered_map<int , size_t > const & errorCounter) {
262
+ switch (code) {
263
+ case fuerte::StatusAccepted:
264
+ case fuerte::StatusCreated: {
265
+ OperationOptions options;
266
+ options.waitForSync = (code == fuerte::StatusCreated);
267
+ return OperationResult (Result (), std::move (body), options, errorCounter);
268
+ }
269
+ case fuerte::StatusConflict:
270
+ return OperationResult (network::resultFromBody (body, TRI_ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED),
271
+ body, options, errorCounter);
272
+ case fuerte::StatusPreconditionFailed:
273
+ return OperationResult (network::resultFromBody (body, TRI_ERROR_ARANGO_CONFLICT),
274
+ body, options, errorCounter);
275
+ case fuerte::StatusNotFound:
276
+ return network::opResultFromBody (body, TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND);
277
+ default : {
278
+ return network::opResultFromBody (body, TRI_ERROR_INTERNAL);
279
+ }
272
280
}
273
281
}
274
282
} // namespace network
0 commit comments