Skip to content

Commit 8535184

Browse files
author
mpv1989
committed
Fix issue #133
1 parent 173980d commit 8535184

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/main/java/com/arangodb/ArangoCollection.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ public <T> T getDocument(final String key, final Class<T> type, final DocumentRe
242242
if (LOGGER.isDebugEnabled()) {
243243
LOGGER.debug(e.getMessage(), e);
244244
}
245-
if (options == null || options.isCatchException()) {
245+
if ((e.getResponseCode() != null && (e.getResponseCode().intValue() == 404
246+
|| e.getResponseCode().intValue() == 304 || e.getResponseCode().intValue() == 412))
247+
&& (options == null || options.isCatchException())) {
246248
return null;
247249
}
248250
throw e;
@@ -532,7 +534,9 @@ public Boolean documentExists(final String key, final DocumentExistsOptions opti
532534
executor.execute(documentExistsRequest(key, options), VPackSlice.class);
533535
return true;
534536
} catch (final ArangoDBException e) {
535-
if (options == null || options.isCatchException()) {
537+
if ((e.getResponseCode() != null && (e.getResponseCode().intValue() == 404
538+
|| e.getResponseCode().intValue() == 304 || e.getResponseCode().intValue() == 412))
539+
&& (options == null || options.isCatchException())) {
536540
return false;
537541
}
538542
throw e;

src/main/java/com/arangodb/ArangoDBException.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ArangoDBException extends RuntimeException {
3030

3131
private static final long serialVersionUID = 6165638002614173801L;
3232
private ErrorEntity entity = null;
33+
private Integer responseCode;
3334

3435
public ArangoDBException(final ErrorEntity errorEntity) {
3536
super(String.format("Response: %s, Error: %s - %s", errorEntity.getCode(), errorEntity.getErrorNum(),
@@ -41,6 +42,11 @@ public ArangoDBException(final String message) {
4142
super(message);
4243
}
4344

45+
public ArangoDBException(final String message, final Integer responseCode) {
46+
super(message);
47+
this.responseCode = responseCode;
48+
}
49+
4450
public ArangoDBException(final Throwable cause) {
4551
super(cause);
4652
}
@@ -54,7 +60,7 @@ public String getException() {
5460
}
5561

5662
public Integer getResponseCode() {
57-
return entity != null ? entity.getCode() : null;
63+
return responseCode != null ? responseCode : entity != null ? entity.getCode() : null;
5864
}
5965

6066
public Integer getErrorNum() {

src/main/java/com/arangodb/internal/http/HttpCommunication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ protected void checkError(final Response response) throws ArangoDBException {
381381
final ErrorEntity errorEntity = util.deserialize(response.getBody(), ErrorEntity.class);
382382
throw new ArangoDBException(errorEntity);
383383
} else {
384-
throw new ArangoDBException(String.format("Response Code: %s", response.getResponseCode()));
384+
throw new ArangoDBException(String.format("Response Code: %s", response.getResponseCode()),
385+
response.getResponseCode());
385386
}
386387
}
387388
} catch (final VPackParserException e) {

src/main/java/com/arangodb/internal/velocystream/VstCommunication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ protected void checkError(final Response response) throws ArangoDBException {
105105
final ErrorEntity errorEntity = util.deserialize(response.getBody(), ErrorEntity.class);
106106
throw new ArangoDBException(errorEntity);
107107
} else {
108-
throw new ArangoDBException(String.format("Response Code: %s", response.getResponseCode()));
108+
throw new ArangoDBException(String.format("Response Code: %s", response.getResponseCode()),
109+
response.getResponseCode());
109110
}
110111
}
111112
} catch (final VPackParserException e) {

0 commit comments

Comments
 (0)