diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c1c12e4b..1bf188812 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +## [0.7.8] - 2023-10-13 + +### Fixed + +- Fixed a bug to preserve the user defined error instead of converting it to generic ApiException. + ## [0.7.7] - 2023-10-12 ### Added diff --git a/components/abstractions/src/main/java/com/microsoft/kiota/ApiExceptionBuilder.java b/components/abstractions/src/main/java/com/microsoft/kiota/ApiExceptionBuilder.java index f2ec5d1e3..3b61d8f13 100644 --- a/components/abstractions/src/main/java/com/microsoft/kiota/ApiExceptionBuilder.java +++ b/components/abstractions/src/main/java/com/microsoft/kiota/ApiExceptionBuilder.java @@ -1,8 +1,10 @@ package com.microsoft.kiota; +import com.microsoft.kiota.serialization.Parsable; import jakarta.annotation.Nonnull; import java.util.Objects; +import java.util.function.Supplier; /** Builder class for ApiException. */ public class ApiExceptionBuilder { @@ -17,11 +19,18 @@ public ApiExceptionBuilder() { /** * Constructs an ApiExceptionBuilder starting from a base ApiException - * @param base The original ApiException to be used as a base. + * @param builder A builder for the ApiException to be used as a base. */ - public ApiExceptionBuilder(@Nonnull final ApiException base) { - Objects.requireNonNull(base); - value = new ApiException(base.getMessage(), base.getCause()); + public ApiExceptionBuilder(@Nonnull final Supplier builder) { + Objects.requireNonNull(builder); + final Parsable error = builder.get(); + if (error instanceof ApiException) { + value = (ApiException) error; + } else { + value = new ApiExceptionBuilder() + .withMessage("\"unexpected error type \" + error.getClass().getName()") + .build(); + } } /** diff --git a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java index c676a037b..222b17e6b 100644 --- a/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java +++ b/components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java @@ -625,15 +625,7 @@ private Response throwIfFailedResponse(@Nonnull final Response response, @Nonnul spanForAttributes.setAttribute(errorBodyFoundAttributeName, true); final Span deserializationSpan = GlobalOpenTelemetry.getTracer(obsOptions.getTracerInstrumentationName()).spanBuilder("getObjectValue").setParent(Context.current().with(span)).startSpan(); try(final Scope deserializationScope = deserializationSpan.makeCurrent()) { - final Parsable error = rootNode.getObjectValue(errorClass); - ApiExceptionBuilder resultBuilder; - if (error instanceof ApiException) { - resultBuilder = new ApiExceptionBuilder((ApiException)error); - } else { - resultBuilder = new ApiExceptionBuilder() - .withMessage("unexpected error type " + error.getClass().getName()); - } - ApiException result = resultBuilder + ApiException result = new ApiExceptionBuilder(() -> rootNode.getObjectValue(errorClass)) .withResponseStatusCode(statusCode) .withResponseHeaders(responseHeaders) .build(); diff --git a/gradle.properties b/gradle.properties index 022daf21d..3ca9f26ee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ org.gradle.caching=true mavenGroupId = com.microsoft.kiota mavenMajorVersion = 0 mavenMinorVersion = 7 -mavenPatchVersion = 7 +mavenPatchVersion = 8 mavenArtifactSuffix = #These values are used to run functional tests