diff --git a/sdk/appconfiguration/azure-data-appconfiguration-v2/pom.xml b/sdk/appconfiguration/azure-data-appconfiguration-v2/pom.xml
index a66aca2b04a6..fc7837e6282f 100644
--- a/sdk/appconfiguration/azure-data-appconfiguration-v2/pom.xml
+++ b/sdk/appconfiguration/azure-data-appconfiguration-v2/pom.xml
@@ -48,6 +48,11 @@ Code generated by Microsoft (R) TypeSpec Code Generator.
0.10
+
+ io.clientcore
+ core
+ 1.0.0-beta.10
+
com.azure.v2
azure-core
diff --git a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/ConfigurationClient.java b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/ConfigurationClient.java
index 0f96741d71db..6c74b1cc7222 100644
--- a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/ConfigurationClient.java
+++ b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/ConfigurationClient.java
@@ -657,7 +657,8 @@ public Response getConfigurationSettingWithResponse(Config
return new Response<>(httpResponse.getRequest(), httpResponse.getStatusCode(),
httpResponse.getHeaders(), null);
}
- throw LOGGER.logThrowableAsError(ex);
+ // HttpResponseException is logged in the instrumentation policy.
+ throw ex;
}
}
@@ -994,7 +995,7 @@ public PagedIterable listConfigurationSettings(SettingSele
acceptDateTime, settingFields, null, null, getPageETag(matchConditionsList, pageETagIndex),
tagsFilter, context);
} catch (HttpResponseException ex) {
- return handleNotModifiedErrorToValidResponse(ex, LOGGER);
+ return handleNotModifiedErrorToValidResponse(ex);
}
return toConfigurationSettingWithPagedResponse(pagedResponse);
}, (nextLink, ignored) -> {
@@ -1003,7 +1004,7 @@ acceptDateTime, settingFields, null, null, getPageETag(matchConditionsList, page
pagedResponse = serviceClient.getKeyValuesNextSinglePage(nextLink.getContinuationToken(), null, null,
acceptDateTime, null, getPageETag(matchConditionsList, pageETagIndex), context);
} catch (HttpResponseException ex) {
- return handleNotModifiedErrorToValidResponse(ex, LOGGER);
+ return handleNotModifiedErrorToValidResponse(ex);
}
return toConfigurationSettingWithPagedResponse(pagedResponse);
});
diff --git a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/ConfigurationClientBuilder.java b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/ConfigurationClientBuilder.java
index 94876459273f..58f915a096ae 100644
--- a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/ConfigurationClientBuilder.java
+++ b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/ConfigurationClientBuilder.java
@@ -302,8 +302,8 @@ public ConfigurationClientBuilder audience(ConfigurationAudience audience) {
private AzureAppConfigurationClientImpl buildInnerClient() {
// Manual changes start
if (isNullOrEmpty(connectionString) && isNullOrEmpty(endpoint)) {
- throw LOGGER
- .logThrowableAsError(new IllegalArgumentException("'connectionString' or 'endpoint' cannot be null."));
+ throw LOGGER.throwableAtError()
+ .log("'connectionString' or 'endpoint' cannot be null.", IllegalArgumentException::new);
}
if (!isNullOrEmpty(connectionString) && isNullOrEmpty(endpoint)) {
@@ -346,8 +346,8 @@ private HttpPipeline createHttpPipeline() {
} else if (connectionStringCredentials != null) {
policies.add(new ConfigurationCredentialsPolicy(connectionStringCredentials));
} else {
- throw LOGGER.logThrowableAsError(
- new IllegalArgumentException("Missing credential information while building a client."));
+ throw LOGGER.throwableAtError()
+ .log("Missing credential information while building a client.", IllegalArgumentException::new);
}
// Manual changes end
diff --git a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/ConfigurationClientCredentials.java b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/ConfigurationClientCredentials.java
index 6e5b83c29fc3..5464079dedd0 100644
--- a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/ConfigurationClientCredentials.java
+++ b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/ConfigurationClientCredentials.java
@@ -6,6 +6,7 @@
import io.clientcore.core.http.models.HttpHeaders;
import io.clientcore.core.http.models.HttpRequest;
import io.clientcore.core.instrumentation.logging.ClientLogger;
+import io.clientcore.core.models.CoreException;
import io.clientcore.core.models.binarydata.BinaryData;
import io.clientcore.core.utils.DateTimeRfc1123;
@@ -100,10 +101,8 @@ void setAuthorizationHeaders(HttpRequest httpRequest) {
= Base64.getEncoder().encodeToString(sha256HMAC.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8)));
headers.set(HttpHeaderName.AUTHORIZATION, "HMAC-SHA256 Credential=" + credentials.id()
+ "&SignedHeaders=Host;Date;x-ms-content-sha256&Signature=" + signature);
- } catch (GeneralSecurityException e) {
- throw LOGGER.logThrowableAsError(new RuntimeException(e));
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
+ } catch (GeneralSecurityException | MalformedURLException e) {
+ throw LOGGER.throwableAtError().log(e, CoreException::from);
}
}
diff --git a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/ConfigurationSettingDeserializationHelper.java b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/ConfigurationSettingDeserializationHelper.java
index d8d6d3138a3e..5d08b6d020c1 100644
--- a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/ConfigurationSettingDeserializationHelper.java
+++ b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/ConfigurationSettingDeserializationHelper.java
@@ -11,6 +11,7 @@
import io.clientcore.core.http.models.Response;
import io.clientcore.core.http.paging.PagedResponse;
import io.clientcore.core.instrumentation.logging.ClientLogger;
+import io.clientcore.core.models.CoreException;
import io.clientcore.core.serialization.json.JsonReader;
import io.clientcore.core.serialization.json.JsonToken;
@@ -99,11 +100,12 @@ public static ConfigurationSetting toConfigurationSetting(KeyValue keyValue) {
// Configuration Setting
return setting;
}
- } catch (Exception exception) {
- throw LOGGER.logThrowableAsError(
- new RuntimeException("The setting is neither a 'FeatureFlagConfigurationSetting' nor "
- + "'SecretReferenceConfigurationSetting', return the setting as 'ConfigurationSetting'. "
- + "Error: ", exception));
+ } catch (RuntimeException exception) {
+ throw LOGGER.throwableAtError()
+ .log(
+ "The setting is neither a 'FeatureFlagConfigurationSetting' nor "
+ + "'SecretReferenceConfigurationSetting', return the setting as 'ConfigurationSetting'. ",
+ exception, CoreException::from);
}
}
@@ -121,7 +123,7 @@ public static FeatureFlagConfigurationSetting parseFeatureFlagValue(String value
try (JsonReader jsonReader = JsonReader.fromString(valueInJson)) {
return getFeatureFlagPropertyValue(jsonReader);
} catch (IOException e) {
- throw LOGGER.logThrowableAsError(new IllegalStateException(e));
+ throw LOGGER.throwableAtError().log(e, IllegalStateException::new);
}
}
@@ -145,7 +147,7 @@ public static SecretReferenceConfigurationSetting parseSecretReferenceFieldValue
return new SecretReferenceConfigurationSetting(key, secretId);
});
} catch (IOException e) {
- throw LOGGER.logThrowableAsError(new IllegalStateException(e));
+ throw LOGGER.throwableAtError().log(e, IllegalStateException::new);
}
}
diff --git a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/SyncToken.java b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/SyncToken.java
index 1f714ea9d720..368afcbea52b 100644
--- a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/SyncToken.java
+++ b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/SyncToken.java
@@ -43,12 +43,12 @@ public final class SyncToken {
public static SyncToken createSyncToken(String syncToken) {
final SyncToken token = new SyncToken();
if (CoreUtils.isNullOrEmpty(syncToken)) {
- throw LOGGER.logThrowableAsError(new IllegalArgumentException(CANNOT_EMPTY_OR_NULL));
+ throw LOGGER.throwableAtError().log(CANNOT_EMPTY_OR_NULL, IllegalArgumentException::new);
}
final String[] syncTokenParts = syncToken.split(SEMICOLON, 2);
if (syncTokenParts.length != 2) {
- throw LOGGER.logThrowableAsError(new IllegalArgumentException(VALID_FORMAT_ERROR_MESSAGE));
+ throw LOGGER.throwableAtError().log(VALID_FORMAT_ERROR_MESSAGE, IllegalArgumentException::new);
}
final String[] idParts = syncTokenParts[0].split(EQUAL, 2);
@@ -59,13 +59,13 @@ public static SyncToken createSyncToken(String syncToken) {
|| idParts[1].isEmpty()
|| snParts[0].isEmpty()
|| snParts[1].isEmpty()) {
- throw LOGGER.logThrowableAsError(new IllegalArgumentException(VALID_FORMAT_ERROR_MESSAGE));
+ throw LOGGER.throwableAtError().log(VALID_FORMAT_ERROR_MESSAGE, IllegalArgumentException::new);
}
try {
token.sequenceNumber = Long.parseLong(snParts[1]);
} catch (NumberFormatException ex) {
- throw LOGGER.logThrowableAsError(new IllegalArgumentException(SEQUENCE_NUMBER_CANNOT_PARSED));
+ throw LOGGER.throwableAtError().log(SEQUENCE_NUMBER_CANNOT_PARSED, IllegalArgumentException::new);
}
token.id = idParts[0];
token.value = idParts[1];
diff --git a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/SyncTokenPolicy.java b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/SyncTokenPolicy.java
index c43335d96fd8..aeb034f0772b 100644
--- a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/SyncTokenPolicy.java
+++ b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/SyncTokenPolicy.java
@@ -61,8 +61,7 @@ public void updateSyncToken(String token) {
final SyncToken syncToken;
try {
syncToken = SyncToken.createSyncToken(syncTokenString);
- } catch (Exception ex) {
- logger.logThrowableAsWarning(ex);
+ } catch (RuntimeException ex) {
continue;
}
diff --git a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/Utility.java b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/Utility.java
index 9808ed540e96..9a3468092d03 100644
--- a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/Utility.java
+++ b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/implementation/Utility.java
@@ -11,7 +11,6 @@
import io.clientcore.core.http.models.HttpResponseException;
import io.clientcore.core.http.models.Response;
import io.clientcore.core.http.paging.PagedResponse;
-import io.clientcore.core.instrumentation.logging.ClientLogger;
import io.clientcore.core.models.binarydata.BinaryData;
import io.clientcore.core.utils.CoreUtils;
@@ -118,20 +117,19 @@ public static String parseNextLink(String nextLink) {
}
// Sync Handler
- public static PagedResponse handleNotModifiedErrorToValidResponse(HttpResponseException error,
- ClientLogger logger) {
+ public static PagedResponse
+ handleNotModifiedErrorToValidResponse(HttpResponseException error) {
Response httpResponse = error.getResponse();
- if (httpResponse == null) {
- throw logger.logThrowableAsError(error);
+ if (httpResponse != null) {
+ String continuationToken = parseNextLink(httpResponse.getHeaders().getValue(HttpHeaderName.LINK));
+ if (httpResponse.getStatusCode() == 304) {
+ return new PagedResponse<>(httpResponse.getRequest(), httpResponse.getStatusCode(),
+ httpResponse.getHeaders(), null, continuationToken, null, null, null, null);
+ }
}
- String continuationToken = parseNextLink(httpResponse.getHeaders().getValue(HttpHeaderName.LINK));
- if (httpResponse.getStatusCode() == 304) {
- return new PagedResponse<>(httpResponse.getRequest(), httpResponse.getStatusCode(),
- httpResponse.getHeaders(), null, continuationToken, null, null, null, null);
- }
-
- throw logger.logThrowableAsError(error);
+ // HttpResponseException is already logged in instrumentation policy
+ throw error;
}
// Get the ETag from a list
diff --git a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/models/FeatureFlagConfigurationSetting.java b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/models/FeatureFlagConfigurationSetting.java
index 2f97299985f1..3b61a16a7080 100644
--- a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/models/FeatureFlagConfigurationSetting.java
+++ b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/models/FeatureFlagConfigurationSetting.java
@@ -5,6 +5,7 @@
import com.azure.v2.data.appconfiguration.implementation.Conditions;
import io.clientcore.core.instrumentation.logging.ClientLogger;
+import io.clientcore.core.models.CoreException;
import io.clientcore.core.serialization.json.JsonReader;
import io.clientcore.core.serialization.json.JsonToken;
import io.clientcore.core.serialization.json.JsonWriter;
@@ -84,10 +85,9 @@ public FeatureFlagConfigurationSetting(String featureId, boolean isEnabled) {
public String getValue() {
// Lazily update: Update 'value' by all latest property values when this getValue() method is called.
String newValue = null;
- try {
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- final JsonWriter writer = JsonWriter.toStream(outputStream);
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ JsonWriter writer = JsonWriter.toStream(outputStream)) {
final Set knownProperties = new LinkedHashSet<>(requiredOrOptionalJsonProperties);
writer.writeStartObject();
@@ -105,7 +105,7 @@ public String getValue() {
writer.writeUntypedField(name, jsonValue);
}
} catch (IOException e) {
- throw LOGGER.logThrowableAsError(new RuntimeException(e));
+ throw LOGGER.throwableAtError().log(e, CoreException::from);
}
}
// Remaining known properties we are not processed yet after 'parsedProperties'.
@@ -116,10 +116,9 @@ public String getValue() {
writer.flush();
newValue = outputStream.toString(StandardCharsets.UTF_8.name());
- outputStream.close();
} catch (IOException exception) {
- LOGGER.logThrowableAsError(
- new IllegalArgumentException("Can't parse Feature Flag configuration setting value.", exception));
+ throw LOGGER.throwableAtError()
+ .log("Can't parse Feature Flag configuration setting value.", exception, CoreException::from);
}
super.setValue(newValue);
@@ -361,8 +360,11 @@ public FeatureFlagConfigurationSetting addClientFilter(FeatureFlagFilter clientF
private void checkValid() {
if (!isValidFeatureFlagValue) {
- throw LOGGER.logThrowableAsError(new IllegalArgumentException("The content of the " + super.getValue()
- + " property do not represent a valid feature flag configuration setting."));
+ throw LOGGER.throwableAtError()
+ .log(
+ "The content of the " + super.getValue()
+ + " property do not represent a valid feature flag configuration setting.",
+ IllegalArgumentException::new);
}
}
@@ -483,7 +485,7 @@ private void tryParseValue(String value) {
});
} catch (IOException e) {
isValidFeatureFlagValue = false;
- throw LOGGER.logThrowableAsError(new IllegalArgumentException(e));
+ throw LOGGER.throwableAtError().log(e, IllegalArgumentException::new);
}
}
}
diff --git a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/models/SecretReferenceConfigurationSetting.java b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/models/SecretReferenceConfigurationSetting.java
index e76d5fbd8b11..8c30021fce1c 100644
--- a/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/models/SecretReferenceConfigurationSetting.java
+++ b/sdk/appconfiguration/azure-data-appconfiguration-v2/src/main/java/com/azure/v2/data/appconfiguration/models/SecretReferenceConfigurationSetting.java
@@ -4,6 +4,7 @@
package com.azure.v2.data.appconfiguration.models;
import io.clientcore.core.instrumentation.logging.ClientLogger;
+import io.clientcore.core.models.CoreException;
import io.clientcore.core.serialization.json.JsonReader;
import io.clientcore.core.serialization.json.JsonToken;
import io.clientcore.core.serialization.json.JsonWriter;
@@ -90,10 +91,9 @@ public SecretReferenceConfigurationSetting setKey(String key) {
public String getValue() {
// Lazily update: Update 'value' by all latest property values when this getValue() method is called.
String newValue = null;
- try {
- final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- final JsonWriter writer = JsonWriter.toStream(outputStream);
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ JsonWriter writer = JsonWriter.toStream(outputStream)) {
boolean isUriWritten = false;
writer.writeStartObject();
@@ -112,7 +112,7 @@ public String getValue() {
writer.writeUntypedField(name, jsonValue);
}
} catch (IOException e) {
- throw LOGGER.logThrowableAsError(new RuntimeException(e));
+ throw LOGGER.throwableAtError().log(e, CoreException::from);
}
}
@@ -124,10 +124,9 @@ public String getValue() {
writer.flush();
newValue = outputStream.toString(StandardCharsets.UTF_8.name());
- outputStream.close();
} catch (IOException exception) {
- LOGGER.logThrowableAsError(
- new IllegalArgumentException("Can't parse Secret Reference configuration setting value.", exception));
+ throw LOGGER.throwableAtError()
+ .log("Can't parse Secret Reference configuration setting value.", exception, CoreException::from);
}
super.setValue(newValue);
@@ -201,8 +200,11 @@ public SecretReferenceConfigurationSetting setTags(Map tags) {
private void checkValid() {
if (!isValidSecretReferenceValue) {
- throw LOGGER.logThrowableAsError(new IllegalArgumentException("The content of the " + super.getValue()
- + " property do not represent a valid secret reference configuration setting."));
+ throw LOGGER.throwableAtError()
+ .log(
+ "The content of the " + super.getValue()
+ + " property do not represent a valid secret reference configuration setting.",
+ IllegalArgumentException::new);
}
}
@@ -239,7 +241,7 @@ private void tryParseValue(String value) {
});
} catch (IOException e) {
isValidSecretReferenceValue = false;
- throw LOGGER.logThrowableAsError(new IllegalArgumentException(e));
+ throw LOGGER.throwableAtError().log(e, IllegalArgumentException::new);
}
}
}