Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 01b63b3

Browse files
committed
ArangoDBException factory methods refactoring
1 parent 48f06fe commit 01b63b3

24 files changed

+101
-52
lines changed

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

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.arangodb.entity.ErrorEntity;
2424

25+
import java.util.Objects;
2526
import java.util.concurrent.CompletionException;
2627

2728
/**
@@ -56,46 +57,94 @@ public ArangoDBException(final String message, final Integer responseCode) {
5657
this.requestId = null;
5758
}
5859

60+
/**
61+
* @deprecated use {@link com.arangodb.ArangoDBException#of(java.lang.Throwable)} instead
62+
*/
63+
@Deprecated
5964
public ArangoDBException(final Throwable cause) {
6065
super(cause);
6166
this.entity = null;
6267
this.responseCode = null;
6368
this.requestId = null;
6469
}
6570

71+
/**
72+
* @deprecated use {@link com.arangodb.ArangoDBException#of(String, Throwable)} instead
73+
*/
74+
@Deprecated
6675
public ArangoDBException(final String message, final Throwable cause) {
6776
super(message, cause);
6877
this.entity = null;
6978
this.responseCode = null;
7079
this.requestId = null;
7180
}
7281

82+
/**
83+
* @deprecated use {@link com.arangodb.ArangoDBException#of(Throwable, Long)} instead
84+
*/
85+
@Deprecated
7386
public ArangoDBException(Throwable cause, long requestId) {
7487
super(cause);
7588
this.entity = null;
7689
this.responseCode = null;
7790
this.requestId = requestId;
7891
}
7992

80-
private ArangoDBException(final ArangoDBException e) {
81-
super(e.getMessage(), e);
82-
this.entity = e.entity;
83-
this.responseCode = e.responseCode;
84-
this.requestId = e.requestId;
93+
private ArangoDBException(
94+
String message,
95+
Throwable cause,
96+
ErrorEntity entity,
97+
Integer responseCode,
98+
Long requestId
99+
) {
100+
super(message, cause);
101+
this.entity = entity;
102+
this.responseCode = responseCode;
103+
this.requestId = requestId;
104+
}
105+
106+
public static ArangoDBException of(Throwable t) {
107+
return of(null, t);
108+
}
109+
110+
public static ArangoDBException of(String message, Throwable t) {
111+
return of(message, t, null);
112+
}
113+
114+
public static ArangoDBException of(Throwable t, Long requestId) {
115+
return of(null, t, requestId);
85116
}
86117

87-
public static ArangoDBException wrap(Throwable t) {
118+
private static ArangoDBException of(String message, Throwable t, Long requestId) {
119+
Objects.requireNonNull(t);
120+
Throwable cause = unwrapCause(t);
121+
String msg = message != null ? message
122+
: t.getMessage() != null ? t.getMessage()
123+
: cause.getMessage();
124+
ErrorEntity entity = null;
125+
Integer responseCode = null;
126+
Long reqId = requestId;
127+
88128
if (t instanceof ArangoDBException) {
89-
if (t.getCause() == null) {
90-
return new ArangoDBException((ArangoDBException) t);
91-
} else {
92-
return wrap(t.getCause());
93-
}
94-
} else if (t instanceof CompletionException) {
95-
return wrap(t.getCause());
96-
} else {
97-
return new ArangoDBException(t);
129+
entity = ((ArangoDBException) t).entity;
130+
responseCode = ((ArangoDBException) t).responseCode;
131+
reqId = reqId != null ? reqId : ((ArangoDBException) t).requestId;
132+
}
133+
134+
return new ArangoDBException(
135+
msg,
136+
cause,
137+
entity,
138+
responseCode,
139+
reqId
140+
);
141+
}
142+
143+
private static Throwable unwrapCause(Throwable t) {
144+
if (t instanceof ArangoDBException || t instanceof CompletionException) {
145+
return unwrapCause(t.getCause());
98146
}
147+
return t;
99148
}
100149

101150
/**

‎core/src/main/java/com/arangodb/internal/ArangoCollectionAsyncImpl.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ <T> T catchGetDocumentExceptions(Throwable err) {
334334
return null;
335335
}
336336
}
337-
throw ArangoDBException.wrap(e);
337+
throw ArangoDBException.of(e);
338338
}
339339

340340
@Override
@@ -405,7 +405,7 @@ public CompletableFuture<Boolean> exists() {
405405
return false;
406406
}
407407
}
408-
throw ArangoDBException.wrap(e);
408+
throw ArangoDBException.of(e);
409409
});
410410
}
411411

‎core/src/main/java/com/arangodb/internal/ArangoDatabaseAsyncImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public CompletableFuture<Boolean> exists() {
7979
}
8080
}
8181

82-
throw ArangoDBException.wrap(e);
82+
throw ArangoDBException.of(e);
8383
});
8484
}
8585

‎core/src/main/java/com/arangodb/internal/ArangoExecutor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void disconnect() {
5050
try {
5151
protocol.close();
5252
} catch (final IOException e) {
53-
throw ArangoDBException.wrap(e);
53+
throw ArangoDBException.of(e);
5454
}
5555
}
5656

‎core/src/main/java/com/arangodb/internal/ArangoExecutorAsync.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public <T> CompletableFuture<T> execute(
5858
return protocol.executeAsync(interceptRequest(request), hostHandle)
5959
.handle((r, e) -> {
6060
if (e != null) {
61-
throw ArangoDBException.wrap(e);
61+
throw ArangoDBException.of(e);
6262
} else {
6363
interceptResponse(r);
6464
return responseDeserializer.deserialize(r);

‎core/src/main/java/com/arangodb/internal/ArangoGraphAsyncImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public CompletableFuture<Boolean> exists() {
5858
return false;
5959
}
6060
}
61-
throw ArangoDBException.wrap(e);
61+
throw ArangoDBException.of(e);
6262
});
6363
}
6464

‎core/src/main/java/com/arangodb/internal/ArangoSearchAsyncImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public CompletableFuture<Boolean> exists() {
5858
return false;
5959
}
6060
}
61-
throw ArangoDBException.wrap(e);
61+
throw ArangoDBException.of(e);
6262
});
6363
}
6464

‎core/src/main/java/com/arangodb/internal/ArangoViewAsyncImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public CompletableFuture<Boolean> exists() {
5454
return false;
5555
}
5656
}
57-
throw ArangoDBException.wrap(e);
57+
throw ArangoDBException.of(e);
5858
});
5959
}
6060

‎core/src/main/java/com/arangodb/internal/SearchAliasAsyncImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public CompletableFuture<Boolean> exists() {
5858
return false;
5959
}
6060
}
61-
throw ArangoDBException.wrap(e);
61+
throw ArangoDBException.of(e);
6262
});
6363
}
6464

‎core/src/main/java/com/arangodb/internal/config/ArangoConfigPropertiesImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private Properties initProperties(String fileName) {
4848
try (InputStream is = getClass().getClassLoader().getResourceAsStream(fileName)) {
4949
p.load(is);
5050
} catch (Exception e) {
51-
throw newArangoDBException("Got exception while reading properties file " + fileName, e);
51+
throw ArangoDBException.of("Got exception while reading properties file " + fileName, e);
5252
}
5353
return p;
5454
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /