Skip to content

Commit 8f7fb71

Browse files
committed
Instance methods for Copy functions in Errors
1 parent 156aaa9 commit 8f7fb71

File tree

5 files changed

+27
-31
lines changed

5 files changed

+27
-31
lines changed

src/main/java/com/microsoft/graph/http/GraphError.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,15 @@ protected String transformErrorCodeCase(@Nonnull final String original) {
8888
}
8989

9090
/**
91-
* Makes a deep copy of specified error
92-
* @param error The error we wish to copy
93-
* @return The copy of the specified error
91+
* Makes a deep copy of this GraphError
92+
* @return The copy of this GraphError
9493
*/
95-
public static final GraphError graphErrorCopy(GraphError error) {
94+
public final GraphError copy() {
9695
GraphError errorCopy = new GraphError();
97-
errorCopy.message = error.message;
98-
errorCopy.code = error.code;
99-
if(error.innererror!=null) {
100-
errorCopy.innererror = GraphInnerError.graphInnerErrorCopy(error.innererror);
96+
errorCopy.message = this.message;
97+
errorCopy.code = this.code;
98+
if(this.innererror != null) {
99+
errorCopy.innererror = this.innererror.copy();
101100
}
102101
return errorCopy;
103102
}

src/main/java/com/microsoft/graph/http/GraphErrorResponse.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,14 @@ public final AdditionalDataManager additionalDataManager() {
7373
}
7474

7575
/**
76-
* Make a deep copy the specified GraphErrorResponse object.
77-
* @param response The GraphErrorResponse we want to copy
78-
* @return The copy of the specified GraphErrorResponse
76+
* Make and return a deep copy of this GraphErrorResponse.
77+
* @return The copy of this GraphErrorResponse.
7978
*/
80-
public static GraphErrorResponse getErrorResponseCopy(GraphErrorResponse response)
81-
{
82-
GraphErrorResponse copy = new GraphErrorResponse();
83-
copy.additionalDataManager = response.additionalDataManager(); //We are okay with keeping the dataManager intact
84-
copy.rawObject = response.rawObject.deepCopy();
85-
copy.error = GraphError.graphErrorCopy(response.error);
86-
return copy;
79+
public GraphErrorResponse copy() {
80+
GraphErrorResponse responseCopy = new GraphErrorResponse();
81+
responseCopy.additionalDataManager = this.additionalDataManager;
82+
responseCopy.rawObject = this.rawObject.deepCopy();
83+
responseCopy.error = this.error.copy();
84+
return responseCopy;
8785
}
8886
}

src/main/java/com/microsoft/graph/http/GraphInnerError.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,18 @@ public class GraphInnerError {
6262
public GraphInnerError innererror;
6363

6464
/**
65-
* Make a deep copy of the specified GraphInnerError, this includes all it's subsequent InnerError's.
66-
* @param InnerError The InnerError we want to copy.
67-
* @return The copy of the specified InnerError
65+
* Make a deep copy this GraphInnerError, this includes all it's subsequent InnerError's.
66+
* @return The copy of this InnerError
6867
*/
69-
public static final GraphInnerError graphInnerErrorCopy(GraphInnerError InnerError) {
68+
public final GraphInnerError copy() {
7069
GraphInnerError innerErrorCopy = new GraphInnerError();
71-
innerErrorCopy.code = InnerError.code;
72-
innerErrorCopy.errorType = InnerError.errorType;
73-
innerErrorCopy.debugMessage = InnerError.debugMessage;
74-
innerErrorCopy.stackTrace = InnerError.stackTrace;
75-
innerErrorCopy.throwSite = InnerError.throwSite;
76-
if (InnerError.innererror != null) {
77-
innerErrorCopy.innererror = graphInnerErrorCopy(InnerError.innererror);
70+
innerErrorCopy.code = this.code;
71+
innerErrorCopy.errorType = this.code;
72+
innerErrorCopy.debugMessage = this.debugMessage;
73+
innerErrorCopy.stackTrace = this.stackTrace;
74+
innerErrorCopy.throwSite = this.throwSite;
75+
if(this.innererror != null) {
76+
innerErrorCopy.innererror = this.innererror.copy();
7877
}
7978
return innerErrorCopy;
8079
}

src/main/java/com/microsoft/graph/http/GraphServiceException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public List<String> getResponseHeaders() {
212212
*/
213213
@Nullable
214214
public GraphErrorResponse getError() {
215-
return GraphErrorResponse.getErrorResponseCopy(error);
215+
return this.error.copy();
216216
}
217217

218218
/**

src/test/java/com/microsoft/graph/http/GraphErrorResponseTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void testGraphErrorResponseCopy() {
5050
errorResponse.error = error;
5151

5252
//Copy the errorResponse and its subsequent innerErrors
53-
GraphErrorResponse errorResponseCopy = GraphErrorResponse.getErrorResponseCopy(errorResponse);
53+
GraphErrorResponse errorResponseCopy = errorResponse.copy();
5454
//Ensure subsequent innerErrors have the expected messages in the expected order.
5555
assertEquals(errorResponseCopy.error.message, expectedMessage0);
5656
assertEquals(errorResponseCopy.error.innererror.debugMessage, expectedMessage1);

0 commit comments

Comments
 (0)