Skip to content

Commit 3202b60

Browse files
committed
- fixes a bug where the SDK would be expecting a different casing tahn the service for error codes
1 parent ff459ab commit 3202b60

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.microsoft.graph.core.GraphErrorCodes;
2828
import com.google.gson.annotations.Expose;
29+
import com.google.common.base.CaseFormat;
2930

3031
public class GraphError {
3132

@@ -47,16 +48,24 @@ public class GraphError {
4748
* @return <b>true</b> if the error code matches, and <b>false</b> if there was no match
4849
*/
4950
public boolean isError(final GraphErrorCodes expectedCode) {
50-
if (code.equalsIgnoreCase(expectedCode.toString())) {
51+
if (transformErrorCodeCase(code).equalsIgnoreCase(expectedCode.toString())) {
5152
return true;
5253
}
5354
GraphInnerError innerError = innererror;
5455
while (null != innerError) {
55-
if (innerError.code.equalsIgnoreCase(expectedCode.toString())) {
56+
if (transformErrorCodeCase(innerError.code).equalsIgnoreCase(expectedCode.toString())) {
5657
return true;
5758
}
5859
innerError = innerError.innererror;
5960
}
6061
return false;
6162
}
63+
/**
64+
* Transforms the text error code into the format expected by the value of the enum
65+
* @param original original lowser Camel cased error code
66+
* @return the resulting upper undescore cased error code
67+
*/
68+
protected String transformErrorCodeCase(final String original) {
69+
return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, original);
70+
}
6271
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class GraphErrorTests {
1515
public void testIsError(){
1616
String expectedMessage = "test error message";
1717
GraphError error = new GraphError();
18-
error.code = GraphErrorCodes.ACCESS_DENIED.toString();
18+
error.code = "accessDenied"; // the code prop is lower camel cased https://docs.microsoft.com/en-us/graph/errors#code-property
1919
error.message = expectedMessage;
2020
assertTrue(error.isError(GraphErrorCodes.ACCESS_DENIED));
2121
assertEquals(expectedMessage, error.message);

0 commit comments

Comments
 (0)