|
1 | 1 | // ------------------------------------------------------------------------------ |
2 | 2 | // Copyright (c) 2017 Microsoft Corporation |
3 | | -// |
| 3 | +// |
4 | 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
5 | 5 | // of this software and associated documentation files (the "Software"), to deal |
6 | 6 | // in the Software without restriction, including without limitation the rights |
7 | 7 | // to use, copy, modify, merge, publish, distribute, sub-license, and/or sell |
8 | 8 | // copies of the Software, and to permit persons to whom the Software is |
9 | 9 | // furnished to do so, subject to the following conditions: |
10 | | -// |
| 10 | +// |
11 | 11 | // The above copyright notice and this permission notice shall be included in |
12 | 12 | // all copies or substantial portions of the Software. |
13 | | -// |
| 13 | +// |
14 | 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 | 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
25 | 25 | import com.google.gson.annotations.SerializedName; |
26 | 26 |
|
27 | 27 | import com.microsoft.graph.core.GraphErrorCodes; |
| 28 | +import com.google.common.base.CaseFormat; |
28 | 29 | import com.google.gson.annotations.Expose; |
29 | 30 |
|
30 | 31 | import javax.annotation.Nullable; |
@@ -54,21 +55,30 @@ public class GraphError { |
54 | 55 |
|
55 | 56 | /** |
56 | 57 | * Determine if the given error code is the one that is expected |
57 | | - * |
| 58 | + * |
58 | 59 | * @param expectedCode the expected error code |
59 | 60 | * @return <b>true</b> if the error code matches, and <b>false</b> if there was no match |
60 | 61 | */ |
61 | 62 | public boolean isError(@Nonnull final GraphErrorCodes expectedCode) { |
62 | | - if (code.equalsIgnoreCase(expectedCode.toString())) { |
| 63 | + if (transformErrorCodeCase(code).equalsIgnoreCase(expectedCode.toString())) { |
63 | 64 | return true; |
64 | 65 | } |
65 | 66 | GraphInnerError innerError = innererror; |
66 | 67 | while (null != innerError) { |
67 | | - if (innerError.code.equalsIgnoreCase(expectedCode.toString())) { |
| 68 | + if (transformErrorCodeCase(innerError.code).equalsIgnoreCase(expectedCode.toString())) { |
68 | 69 | return true; |
69 | 70 | } |
70 | 71 | innerError = innerError.innererror; |
71 | 72 | } |
72 | 73 | return false; |
73 | 74 | } |
| 75 | + /** |
| 76 | + * Transforms the text error code into the format expected by the value of the enum |
| 77 | + * @param original original lowser Camel cased error code |
| 78 | + * @return the resulting upper undescore cased error code |
| 79 | + */ |
| 80 | + @Nonnull |
| 81 | + protected String transformErrorCodeCase(@Nonnull final String original) { |
| 82 | + return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, original); |
| 83 | + } |
74 | 84 | } |
0 commit comments