Skip to content

Commit 28666fd

Browse files
committed
Fix cfRayId after merge and test cases
1 parent 02db73f commit 28666fd

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/main/java/com/configcat/ConfigFetcher.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,19 @@ public void onResponse(@NotNull Call call, @NotNull Response response) {
145145
logger.error(1101, formattableLogMessage);
146146
}
147147
} catch (SocketTimeoutException e) {
148-
FormattableLogMessage formattableLogMessage = ConfigCatLogMessages.getFetchFailedDueToRequestTimeout(httpClient.connectTimeoutMillis(), httpClient.readTimeoutMillis(), httpClient.writeTimeoutMillis());
149-
fetchResponse = FetchResponse.failed(formattableLogMessage, false, null, true);
150148
FormattableLogMessage formattableLogMessage = ConfigCatLogMessages.getFetchFailedDueToRequestTimeout(httpClient.connectTimeoutMillis(), httpClient.readTimeoutMillis(), httpClient.writeTimeoutMillis(), cfRayId);
149+
fetchResponse = FetchResponse.failed(formattableLogMessage, false, cfRayId, true);
151150
logger.error(1102, formattableLogMessage, e);
152-
future.complete(FetchResponse.failed(formattableLogMessage, false, cfRayId));
153151
} catch (Exception e) {
154-
String message = ConfigCatLogMessages.FETCH_FAILED_DUE_TO_UNEXPECTED_ERROR;
155-
fetchResponse = FetchResponse.failed(message, false, null, true);
156-
logger.error(1103, message, e);
152+
FormattableLogMessage formattableLogMessage = ConfigCatLogMessages.getFetchFailedDueToUnexpectedError(cfRayId);
153+
fetchResponse = FetchResponse.failed(formattableLogMessage, false, cfRayId, true);
154+
logger.error(1103, formattableLogMessage, e);
157155
} finally {
158156
if(fetchResponse == null) {
159-
fetchResponse = FetchResponse.failed(ConfigCatLogMessages.FETCH_FAILED_DUE_TO_UNEXPECTED_ERROR,false, null, false);
157+
FormattableLogMessage formattableLogMessage = ConfigCatLogMessages.getFetchFailedDueToUnexpectedError(cfRayId);
158+
fetchResponse = FetchResponse.failed(formattableLogMessage,false, cfRayId, false);
160159
}
161160
future.complete(fetchResponse);
162-
FormattableLogMessage formattableLogMessage = ConfigCatLogMessages.getFetchFailedDueToUnexpectedError(cfRayId);
163-
logger.error(1103, formattableLogMessage, e);
164-
future.complete(FetchResponse.failed(formattableLogMessage, false, cfRayId));
165161
}
166162
}
167163
});

src/test/java/com/configcat/ConfigFetcherTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public void fetchTimeOutExceptionContainsCFRayIdIfPresented() throws IOException
100100
PollingModes.manualPoll().getPollingIdentifier());
101101

102102
this.server.enqueue(new MockResponse().setBody("test").setHeader("CF-RAY", "12345").setBodyDelay(2, TimeUnit.SECONDS));
103+
this.server.enqueue(new MockResponse().setBody("test").setHeader("CF-RAY", "12345").setBodyDelay(2, TimeUnit.SECONDS));
104+
103105
FetchResponse response = fetch.fetchAsync(null).get();
104106
assertTrue(response.isFailed());
105107
assertTrue(response.entry().isEmpty());
@@ -126,6 +128,12 @@ public void fetchUnexpectedErrorExceptionContainsCFRayIdIfPresented() throws IOE
126128
false,
127129
PollingModes.manualPoll().getPollingIdentifier());
128130

131+
this.server.enqueue(
132+
new MockResponse()
133+
.setResponseCode(200)
134+
.setHeader("CF-RAY", "12345")
135+
.setBody("test")
136+
.setSocketPolicy(SocketPolicy.DISCONNECT_DURING_RESPONSE_BODY));
129137
this.server.enqueue(
130138
new MockResponse()
131139
.setResponseCode(200)

0 commit comments

Comments
 (0)