Skip to content

Commit a06d46a

Browse files
author
Andrew Omondi
committed
Adds http response code to the api exception
1 parent 2c9f23c commit a06d46a

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
## [0.3.1] - 2023-03-08
15+
16+
# Added
17+
18+
- Adds ResponseStatusCode property to API exception class
19+
1420
## [0.3.0] - 2023-02-21
1521

1622
### Changed

components/abstractions/src/main/java/com/microsoft/kiota/ApiException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ public ApiException(@Nonnull final String message, @Nonnull final Throwable caus
2020
public ApiException(@Nonnull final Throwable cause) {
2121
super(cause);
2222
}
23+
24+
/** The HTTP status code for the response*/
25+
public int responseStatusCode;
2326
}

components/http/okHttp/src/main/java/com/microsoft/kiota/http/OkHttpRequestAdapter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ private Response throwIfFailedResponse(@Nonnull final Response response, @Nonnul
586586
!(statusCode >= 500 && statusCode < 600 && errorMappings.containsKey("5XX"))) {
587587
spanForAttributes.setAttribute(errorMappingFoundAttributeName, false);
588588
final ApiException result = new ApiException("the server returned an unexpected status code and no error class is registered for this code " + statusCode);
589+
result.responseStatusCode = statusCode;
589590
spanForAttributes.recordException(result);
590591
throw result;
591592
}
@@ -603,6 +604,7 @@ private Response throwIfFailedResponse(@Nonnull final Response response, @Nonnul
603604
spanForAttributes.setAttribute(errorBodyFoundAttributeName, false);
604605
closeResponse = false;
605606
final ApiException result = new ApiException("service returned status code" + statusCode + " but no response body was found");
607+
result.responseStatusCode = statusCode;
606608
spanForAttributes.recordException(result);
607609
throw result;
608610
}
@@ -616,6 +618,7 @@ private Response throwIfFailedResponse(@Nonnull final Response response, @Nonnul
616618
} else {
617619
result = new ApiException("unexpected error type " + error.getClass().getName());
618620
}
621+
result.responseStatusCode = statusCode;
619622
spanForAttributes.recordException(result);
620623
throw result;
621624
} finally {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ org.gradle.caching=true
2626
mavenGroupId = com.microsoft.kiota
2727
mavenMajorVersion = 0
2828
mavenMinorVersion = 3
29-
mavenPatchVersion = 0
29+
mavenPatchVersion = 1
3030
mavenArtifactSuffix =
3131

3232
#These values are used to run functional tests

0 commit comments

Comments
 (0)