File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
main/java/com/microsoft/graph/http
test/java/com/microsoft/graph/http Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change 2626
2727import com .microsoft .graph .core .GraphErrorCodes ;
2828import com .google .gson .annotations .Expose ;
29+ import com .google .common .base .CaseFormat ;
2930
3031public 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}
Original file line number Diff line number Diff 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 );
You can’t perform that action at this time.
0 commit comments