Skip to content

Commit

Permalink
PR review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
andrueastman committed Apr 26, 2023
1 parent 0f8b972 commit 0365bed
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.microsoft.kiota;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import javax.annotation.Nonnull;

/** Parent type for exceptions thrown by the client when receiving failed responses to its requests. */
Expand All @@ -29,5 +28,17 @@ public ApiException(@Nonnull final Throwable cause) {

/** The HTTP response headers for the error response*/
@Nonnull
public final ResponseHeaders responseHeaders = new ResponseHeaders();
private ResponseHeaders responseHeaders = new ResponseHeaders();

/** Gets the HTTP response headers for the error response */
public ResponseHeaders getResponseHeaders() {
return new ResponseHeaders(responseHeaders);
}

/** Sets the HTTP response headers for the error response */
public void setResponseHeaders(@Nonnull ResponseHeaders responseHeaders) {
Objects.requireNonNull(responseHeaders);
this.responseHeaders = new ResponseHeaders(responseHeaders);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
import javax.annotation.Nonnull;

class Headers extends CaseInsensitiveMap {
/** Default constructor */
public Headers() {
super();
}

/** Copy constructor */
public Headers(@Nonnull Headers headers) {
super();
Objects.requireNonNull(headers);
putAll(headers);
}

/**
* Adds a header to the current request.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.microsoft.kiota;

import javax.annotation.Nonnull;

/**
* A class representing the headers of a request.
*/
Expand All @@ -7,4 +10,9 @@ public class RequestHeaders extends Headers {
public RequestHeaders() {
super();
}

/** Copy constructor */
public RequestHeaders(@Nonnull RequestHeaders requestHeaders) {
super(requestHeaders);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.microsoft.kiota;

import javax.annotation.Nonnull;

/**
* A class representing the headers of a request.
*/
Expand All @@ -7,4 +10,9 @@ public class ResponseHeaders extends Headers {
public ResponseHeaders() {
super();
}

/** Copy constructor */
public ResponseHeaders(@Nonnull ResponseHeaders responseHeaders) {
super(responseHeaders);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ private Response throwIfFailedResponse(@Nonnull final Response response, @Nonnul
spanForAttributes.setAttribute(errorMappingFoundAttributeName, false);
final ApiException result = new ApiException("the server returned an unexpected status code and no error class is registered for this code " + statusCode);
result.responseStatusCode = statusCode;
result.responseHeaders = responseHeaders;
result.setResponseHeaders(responseHeaders);
spanForAttributes.recordException(result);
throw result;
}
Expand All @@ -614,7 +614,7 @@ private Response throwIfFailedResponse(@Nonnull final Response response, @Nonnul
closeResponse = false;
final ApiException result = new ApiException("service returned status code" + statusCode + " but no response body was found");
result.responseStatusCode = statusCode;
result.responseHeaders = responseHeaders;
result.setResponseHeaders(responseHeaders);
spanForAttributes.recordException(result);
throw result;
}
Expand All @@ -629,7 +629,7 @@ private Response throwIfFailedResponse(@Nonnull final Response response, @Nonnul
result = new ApiException("unexpected error type " + error.getClass().getName());
}
result.responseStatusCode = statusCode;
result.responseHeaders = responseHeaders;
result.setResponseHeaders(responseHeaders);
spanForAttributes.recordException(result);
throw result;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void throwsAPIException() throws Exception {
final var cause = exception.getCause();
assertTrue(cause instanceof ApiException);
assertEquals(404, ((ApiException)cause).responseStatusCode);
assertTrue(((ApiException)cause).responseHeaders.containsKey("request-id"));
assertTrue(((ApiException)cause).getResponseHeaders().containsKey("request-id"));
}
public static OkHttpClient getMockClient(final Response response) throws IOException {
final OkHttpClient mockClient = mock(OkHttpClient.class);
Expand Down

0 comments on commit 0365bed

Please sign in to comment.