@@ -170,39 +170,14 @@ protected ReplicationDumpHeader toReplicationDumpHeader(HttpResponseEntity res)
170170 }
171171
172172 /**
173- * Creates an entity object
174- *
175- * @param res
176- * the response of the database
177- * @param clazz
178- * the class of the entity object
179- * @param pclazz
180- * the class of the object wrapped in the entity object
181- * @param validate
182- * true for validation
183- * @return the result entity object of class T (T extends BaseEntity)
184- * @throws ArangoException
173+ * Checks the Http response for database or server errors
174+ * @param res the response of the database
175+ * @return The Http status code
176+ * @throws ArangoException if any error happened
185177 */
186- protected <T extends BaseEntity > T createEntity (
187- HttpResponseEntity res ,
188- Class <T > clazz ,
189- Class <?>[] pclazz ,
190- boolean validate ) throws ArangoException {
191- if (res == null ) {
192- return null ;
193- }
194- boolean isDocumentEntity = false ;
195- boolean requestSuccessful = true ;
196- // the following was added to ensure, that attributes with a key like
197- // "error", "code", "errorNum"
198- // and "etag" will be serialized, when no error was thrown by the
199- // database
200- if (clazz == DocumentEntity .class ) {
201- isDocumentEntity = true ;
202- }
178+ private int checkServerErrors (HttpResponseEntity res ) throws ArangoException {
203179 int statusCode = res .getStatusCode ();
204- if (statusCode >= 400 ) {
205- requestSuccessful = false ;
180+ if (statusCode >= 400 ) { // always throws ArangoException
206181 DefaultEntity defaultEntity = new DefaultEntity ();
207182 if (res .getText () != null && !res .getText ().equalsIgnoreCase ("" ) && statusCode != 500 ) {
208183 JsonParser jsonParser = new JsonParser ();
@@ -263,7 +238,44 @@ protected <T extends BaseEntity> T createEntity(
263238 arangoException .setCode (statusCode );
264239 throw arangoException ;
265240 }
266-
241+
242+ return statusCode ;
243+ }
244+ /**
245+ * Creates an entity object
246+ *
247+ * @param res
248+ * the response of the database
249+ * @param clazz
250+ * the class of the entity object
251+ * @param pclazz
252+ * the class of the object wrapped in the entity object
253+ * @param validate
254+ * true for validation
255+ * @return the result entity object of class T (T extends BaseEntity)
256+ * @throws ArangoException
257+ */
258+ protected <T extends BaseEntity > T createEntity (
259+ HttpResponseEntity res ,
260+ Class <T > clazz ,
261+ Class <?>[] pclazz ,
262+ boolean validate ) throws ArangoException {
263+ if (res == null ) {
264+ return null ;
265+ }
266+ boolean isDocumentEntity = false ;
267+ //boolean requestSuccessful = true;
268+
269+ // the following was added to ensure, that attributes with a key like
270+ // "error", "code", "errorNum"
271+ // and "etag" will be serialized, when no error was thrown by the
272+ // database
273+ if (clazz == DocumentEntity .class ) {
274+ isDocumentEntity = true ;
275+ }
276+
277+ int statusCode =checkServerErrors (res );
278+
267279 try {
268280 EntityDeserializers .setParameterized (pclazz );
269281
@@ -283,7 +295,7 @@ protected <T extends BaseEntity> T createEntity(
283295 validate (res , entity );
284296 }
285297
286- if (isDocumentEntity && requestSuccessful ) {
298+ if (isDocumentEntity ) { // && requestSuccessful NOTE: no need for this, an exception is always thrown
287299 entity .setCode (statusCode );
288300 entity .setErrorMessage (null );
289301 entity .setError (false );
@@ -295,6 +307,27 @@ protected <T extends BaseEntity> T createEntity(
295307 EntityDeserializers .removeParameterized ();
296308 }
297309 }
310+
311+ /**
312+ * Gets the raw JSON string with results, from the Http response
313+ * @param res the response of the database
314+ * @return A valid JSON string with the results
315+ * @throws ArangoException
316+ */
317+ protected String getJSONResponseText (HttpResponseEntity res ) throws ArangoException {
318+ if (res == null ) {
319+ return null ;
320+ }
321+
322+ checkServerErrors (res );
323+
324+ // no errors, return results as a JSON string
325+ JsonParser jsonParser = new JsonParser ();
326+ JsonElement jsonElement = jsonParser .parse (res .getText ());
327+ JsonObject jsonObject = jsonElement .getAsJsonObject ();
328+ JsonElement result = jsonObject .get ("result" );
329+ return result .toString ();
330+ }
298331
299332 protected <T > T createEntity (String str , Class <T > clazz , Class <?>... pclazz ) throws ArangoException {
300333 try {
0 commit comments