diff --git a/src/main/java/com/microsoft/graph/http/GraphError.java b/src/main/java/com/microsoft/graph/http/GraphError.java
index a436a915c..a4cba2355 100644
--- a/src/main/java/com/microsoft/graph/http/GraphError.java
+++ b/src/main/java/com/microsoft/graph/http/GraphError.java
@@ -1,16 +1,16 @@
// ------------------------------------------------------------------------------
// Copyright (c) 2017 Microsoft Corporation
-//
+//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
-//
+//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
-//
+//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -25,6 +25,7 @@
import com.google.gson.annotations.SerializedName;
import com.microsoft.graph.core.GraphErrorCodes;
+import com.google.common.base.CaseFormat;
import com.google.gson.annotations.Expose;
import javax.annotation.Nullable;
@@ -54,21 +55,30 @@ public class GraphError {
/**
* Determine if the given error code is the one that is expected
- *
+ *
* @param expectedCode the expected error code
* @return true if the error code matches, and false if there was no match
*/
public boolean isError(@Nonnull final GraphErrorCodes expectedCode) {
- if (code.equalsIgnoreCase(expectedCode.toString())) {
+ if (transformErrorCodeCase(code).equalsIgnoreCase(expectedCode.toString())) {
return true;
}
GraphInnerError innerError = innererror;
while (null != innerError) {
- if (innerError.code.equalsIgnoreCase(expectedCode.toString())) {
+ if (transformErrorCodeCase(innerError.code).equalsIgnoreCase(expectedCode.toString())) {
return true;
}
innerError = innerError.innererror;
}
return false;
}
+ /**
+ * Transforms the text error code into the format expected by the value of the enum
+ * @param original original lowser Camel cased error code
+ * @return the resulting upper undescore cased error code
+ */
+ @Nonnull
+ protected String transformErrorCodeCase(@Nonnull final String original) {
+ return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, original);
+ }
}
diff --git a/src/test/java/com/microsoft/graph/http/GraphErrorTests.java b/src/test/java/com/microsoft/graph/http/GraphErrorTests.java
index bde72f3ff..8d5998a51 100644
--- a/src/test/java/com/microsoft/graph/http/GraphErrorTests.java
+++ b/src/test/java/com/microsoft/graph/http/GraphErrorTests.java
@@ -15,7 +15,7 @@ public class GraphErrorTests {
public void testIsError(){
String expectedMessage = "test error message";
GraphError error = new GraphError();
- error.code = GraphErrorCodes.ACCESS_DENIED.toString();
+ error.code = "accessDenied"; // the code prop is lower camel cased https://docs.microsoft.com/en-us/graph/errors#code-property
error.message = expectedMessage;
assertTrue(error.isError(GraphErrorCodes.ACCESS_DENIED));
assertEquals(expectedMessage, error.message);