Skip to content

Commit fc0ec75

Browse files
Replace RuntimeException with FlagsmithRuntimeError (#130)
1 parent b59359c commit fc0ec75

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

src/main/java/com/flagsmith/FlagsmithApiWrapper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.core.type.TypeReference;
44
import com.fasterxml.jackson.databind.node.ObjectNode;
55
import com.flagsmith.config.FlagsmithConfig;
6+
import com.flagsmith.exceptions.FlagsmithRuntimeError;
67
import com.flagsmith.flagengine.environments.EnvironmentModel;
78
import com.flagsmith.flagengine.features.FeatureStateModel;
89
import com.flagsmith.flagengine.identities.traits.TraitModel;
@@ -159,7 +160,7 @@ public Flags getFeatureFlags(boolean doThrow) {
159160
} catch (ExecutionException ee) {
160161
logger.error("Execution failed on fetching Feature flags.", ee);
161162
if (doThrow) {
162-
throw new RuntimeException(ee);
163+
throw new FlagsmithRuntimeError(ee);
163164
}
164165
}
165166

@@ -232,7 +233,7 @@ public Flags identifyUserWithTraits(
232233
} catch (ExecutionException ee) {
233234
logger.error("Execution failed on fetching Feature flags.", ee);
234235
if (doThrow) {
235-
throw new RuntimeException(ee);
236+
throw new FlagsmithRuntimeError(ee);
236237
}
237238
}
238239

@@ -258,7 +259,7 @@ public EnvironmentModel getEnvironment() {
258259
logger.error("Environment loading interrupted.", ie);
259260
} catch (ExecutionException ee) {
260261
logger.error("Execution failed on Environment loading.", ee);
261-
throw new RuntimeException(ee);
262+
throw new FlagsmithRuntimeError(ee);
262263
}
263264

264265
return null;

src/main/java/com/flagsmith/FlagsmithClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.flagsmith.config.FlagsmithConfig;
55
import com.flagsmith.exceptions.FlagsmithApiError;
66
import com.flagsmith.exceptions.FlagsmithClientError;
7+
import com.flagsmith.exceptions.FlagsmithRuntimeError;
78
import com.flagsmith.flagengine.Engine;
89
import com.flagsmith.flagengine.environments.EnvironmentModel;
910
import com.flagsmith.flagengine.features.FeatureStateModel;
@@ -478,7 +479,7 @@ public FlagsmithClient build() {
478479

479480
if (configuration.getEnableLocalEvaluation()) {
480481
if (!apiKey.startsWith("ser.")) {
481-
throw new RuntimeException(
482+
throw new FlagsmithRuntimeError(
482483
"In order to use local evaluation, please generate a server key "
483484
+ "in the environment settings page.");
484485
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.flagsmith.exceptions;
2+
3+
/*
4+
* Custom RuntimeException for use in the Flagsmith client code.
5+
*
6+
* TODO: this only extends RuntimeException to maintain backwards compatibility
7+
* for any implementations that previously caught RuntimeException. We should
8+
* consider changing this in a future major release since it's unnecessary.
9+
*/
10+
public class FlagsmithRuntimeError extends RuntimeException {
11+
12+
public FlagsmithRuntimeError() {
13+
super();
14+
}
15+
16+
public FlagsmithRuntimeError(String message) {
17+
super(message);
18+
}
19+
20+
public FlagsmithRuntimeError(Throwable cause) {
21+
super(cause);
22+
}
23+
}

src/main/java/com/flagsmith/threads/RequestProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
import com.flagsmith.MapperFactory;
88
import com.flagsmith.config.Retry;
99
import com.flagsmith.exceptions.FlagsmithApiError;
10+
import com.flagsmith.exceptions.FlagsmithRuntimeError;
11+
1012
import java.io.IOException;
1113
import java.util.concurrent.CompletableFuture;
1214
import java.util.concurrent.ExecutorService;
1315
import java.util.concurrent.Executors;
1416
import java.util.concurrent.Future;
15-
import lombok.Data;
1617
import okhttp3.Call;
1718
import okhttp3.OkHttpClient;
1819
import okhttp3.Request;
@@ -104,7 +105,7 @@ public <T> Future<T> executeAsync(
104105
localRetry.retryAttempted();
105106
} while (localRetry.isRetry(statusCode));
106107
} catch (Exception e) {
107-
throw new RuntimeException();
108+
throw new FlagsmithRuntimeError();
108109
} finally {
109110
if (!completableFuture.isDone()) {
110111
if (doThrow) {

0 commit comments

Comments
 (0)