Skip to content

Commit 7d0ccc8

Browse files
committed
Try to reproduce the original error.
1 parent 9005d5c commit 7d0ccc8

File tree

5 files changed

+241
-86
lines changed

5 files changed

+241
-86
lines changed

google-api-client/src/main/java/com/google/api/client/googleapis/json/GoogleJsonError.java

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -184,72 +184,72 @@ public ErrorInfo clone() {
184184
}
185185
}
186186

187-
public static class Details {
188-
@Key("@type")
189-
private String type;
190-
191-
@Key private String detail;
192-
@Key private String reason;
193-
@Key private List<ParameterViolations> parameterViolations;
194-
195-
public String getType() {
196-
return type;
197-
}
198-
199-
public void setType(String type) {
200-
this.type = type;
201-
}
202-
203-
public String getDetail() {
204-
return detail;
205-
}
206-
207-
public void setDetail(String detail) {
208-
this.detail = detail;
209-
}
210-
211-
public String getReason() {
212-
return reason;
213-
}
214-
215-
public void setReason(String reason) {
216-
this.reason = reason;
217-
}
218-
219-
public List<ParameterViolations> getParameterViolations() {
220-
return parameterViolations;
221-
}
222-
223-
/**
224-
* Sets parameterViolations list as immutable to prevent exposing mutable state.
225-
*
226-
* @param parameterViolations
227-
*/
228-
public void setParameterViolations(List<ParameterViolations> parameterViolations) {
229-
this.parameterViolations = ImmutableList.copyOf(parameterViolations);
230-
}
231-
}
232-
233-
public static class ParameterViolations {
234-
@Key private String parameter;
235-
@Key private String description;
236-
237-
public String getDescription() {
238-
return description;
239-
}
240-
241-
public void setDescription(String description) {
242-
this.description = description;
243-
}
244-
245-
public String getParameter() {
246-
return parameter;
247-
}
248-
249-
public void setParameter(String parameter) {
250-
this.parameter = parameter;
251-
}
252-
}
187+
// public static class Details {
188+
// @Key("@type")
189+
// private String type;
190+
//
191+
// @Key private String detail;
192+
// @Key private String reason;
193+
// @Key private List<ParameterViolations> parameterViolations;
194+
//
195+
// public String getType() {
196+
// return type;
197+
// }
198+
//
199+
// public void setType(String type) {
200+
// this.type = type;
201+
// }
202+
//
203+
// public String getDetail() {
204+
// return detail;
205+
// }
206+
//
207+
// public void setDetail(String detail) {
208+
// this.detail = detail;
209+
// }
210+
//
211+
// public String getReason() {
212+
// return reason;
213+
// }
214+
//
215+
// public void setReason(String reason) {
216+
// this.reason = reason;
217+
// }
218+
//
219+
// public List<ParameterViolations> getParameterViolations() {
220+
// return parameterViolations;
221+
// }
222+
//
223+
// /**
224+
// * Sets parameterViolations list as immutable to prevent exposing mutable state.
225+
// *
226+
// * @param parameterViolations
227+
// */
228+
// public void setParameterViolations(List<ParameterViolations> parameterViolations) {
229+
// this.parameterViolations = ImmutableList.copyOf(parameterViolations);
230+
// }
231+
// }
232+
//
233+
// public static class ParameterViolations {
234+
// @Key private String parameter;
235+
// @Key private String description;
236+
//
237+
// public String getDescription() {
238+
// return description;
239+
// }
240+
//
241+
// public void setDescription(String description) {
242+
// this.description = description;
243+
// }
244+
//
245+
// public String getParameter() {
246+
// return parameter;
247+
// }
248+
//
249+
// public void setParameter(String parameter) {
250+
// this.parameter = parameter;
251+
// }
252+
// }
253253

254254
/** List of detailed errors or {@code null} for none. */
255255
@Key private List<ErrorInfo> errors;
@@ -260,8 +260,8 @@ public void setParameter(String parameter) {
260260
/** Human-readable explanation of the error or {@code null} for none. */
261261
@Key private String message;
262262

263-
/** Lists type and parameterViolation details of an Exception. */
264-
@Key private List<Details> details;
263+
// /** Lists type and parameterViolation details of an Exception. */
264+
// @Key private List<Details> details;
265265

266266
/**
267267
* Returns the list of detailed errors or {@code null} for none.
@@ -318,19 +318,19 @@ public final void setMessage(String message) {
318318
this.message = message;
319319
}
320320

321-
public List<Details> getDetails() {
322-
return details;
323-
}
324-
325-
/**
326-
* Sets the list of invalid parameter error details as immutable to prevent exposing mutable
327-
* state.
328-
*
329-
* @param details
330-
*/
331-
public void setDetails(List<Details> details) {
332-
this.details = ImmutableList.copyOf(details);
333-
}
321+
// public List<Details> getDetails() {
322+
// return details;
323+
// }
324+
//
325+
// /**
326+
// * Sets the list of invalid parameter error details as immutable to prevent exposing mutable
327+
// * state.
328+
// *
329+
// * @param details
330+
// */
331+
// public void setDetails(List<Details> details) {
332+
// this.details = ImmutableList.copyOf(details);
333+
// }
334334

335335
@Override
336336
public GoogleJsonError set(String fieldName, Object value) {

google-api-client/src/test/java/com/google/api/client/googleapis/json/GoogleJsonErrorTest.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import com.google.api.client.testing.http.MockHttpTransport;
2828
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
2929
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
30+
3031
import java.io.InputStream;
32+
import java.io.InputStreamReader;
3133
import junit.framework.TestCase;
3234

3335
/**
@@ -37,6 +39,7 @@
3739
*/
3840
public class GoogleJsonErrorTest extends TestCase {
3941

42+
public static final com.google.gson.JsonParser JSON_PARSER = new com.google.gson.JsonParser();
4043
static final JsonFactory FACTORY = new GsonFactory();
4144
static final String ERROR =
4245
"{"
@@ -93,6 +96,30 @@ public void testParse() throws Exception {
9396
assertEquals(ERROR, FACTORY.toString(errorResponse));
9497
}
9598

99+
public void testParse_withMultipleErrorTypesInDetails() throws Exception {
100+
InputStream errorContent =
101+
GoogleJsonErrorTest.class.getResourceAsStream("errorWithMultipleTypesInDetails.json");
102+
103+
InputStream expectedContent =
104+
GoogleJsonErrorTest.class.getResourceAsStream("expectedResultErrorWithMultipleTypesInDetails.json");
105+
106+
HttpTransport transport =
107+
new ErrorTransport(
108+
new MockLowLevelHttpResponse()
109+
.setContent(errorContent)
110+
.setContentType(Json.MEDIA_TYPE)
111+
.setStatusCode(HttpStatusCodes.STATUS_CODE_FORBIDDEN));
112+
HttpRequest request =
113+
transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
114+
request.setThrowExceptionOnExecuteError(false);
115+
HttpResponse response = request.execute();
116+
com.google.api.client.googleapis.json.GoogleJsonError errorResponse =
117+
com.google.api.client.googleapis.json.GoogleJsonError.parse(FACTORY, response);
118+
System.out.println(errorResponse.toString());
119+
assertEquals(JSON_PARSER.parse(new InputStreamReader(expectedContent)), JSON_PARSER.parse(FACTORY.toString(errorResponse)));
120+
// assertNotNull(errorResponse.getDetails().get(2).getReason());
121+
}
122+
96123
public void testParse_withDetails() throws Exception {
97124
String DETAILS_ERROR =
98125
"{"
@@ -122,8 +149,8 @@ public void testParse_withDetails() throws Exception {
122149
com.google.api.client.googleapis.json.GoogleJsonError errorResponse =
123150
com.google.api.client.googleapis.json.GoogleJsonError.parse(FACTORY, response);
124151

125-
assertEquals(DETAILS_ERROR, FACTORY.toString(errorResponse));
126-
assertNotNull(errorResponse.getDetails());
152+
assertEquals(JSON_PARSER.parse(DETAILS_ERROR), JSON_PARSER.parse(FACTORY.toString(errorResponse)));
153+
// assertNotNull(errorResponse.getDetails());
127154
}
128155

129156
public void testParse_withReasonInDetails() throws Exception {
@@ -166,7 +193,7 @@ public void testParse_withReasonInDetails() throws Exception {
166193
com.google.api.client.googleapis.json.GoogleJsonError errorResponse =
167194
com.google.api.client.googleapis.json.GoogleJsonError.parse(FACTORY, response);
168195

169-
assertEquals(DETAILS_ERROR, FACTORY.toString(errorResponse));
170-
assertNotNull(errorResponse.getDetails().get(2).getReason());
196+
assertEquals(JSON_PARSER.parse(DETAILS_ERROR), JSON_PARSER.parse(FACTORY.toString(errorResponse)));
197+
// assertNotNull(errorResponse.getDetails().get(2).getReason());
171198
}
172199
}

google-api-client/src/test/java/com/google/api/client/googleapis/json/GoogleJsonResponseExceptionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,6 @@ public void testFrom_detailsWithInvalidParameter() throws Exception {
207207
GoogleJsonResponseException ge =
208208
GoogleJsonResponseException.from(
209209
com.google.api.client.googleapis.json.GoogleJsonErrorTest.FACTORY, response);
210-
assertNotNull(ge.getDetails().getDetails());
210+
// assertNotNull(ge.getDetails().getDetails());
211211
}
212212
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"error": {
3+
"code": 400,
4+
"message": "The template parameters are invalid.",
5+
"status": "INVALID_ARGUMENT",
6+
"details": [
7+
{
8+
"@type": "type.googleapis.com/google.dataflow.v1beta3.InvalidTemplateParameters",
9+
"reason": "TEST REASON 1",
10+
"parameterViolations": [
11+
{
12+
"parameter": "safeBrowsingApiKey",
13+
"description": "Parameter didn't match regex '^[0-9a-zA-Z_]+$'"
14+
}
15+
]
16+
},
17+
{
18+
"@type": "type.googleapis.com/google.rpc.DebugInfo",
19+
"detail": "test detail"
20+
},
21+
{
22+
"@type": "type.googleapis.com/google.rpc.DebugInfo",
23+
"reason": "test reason 2"
24+
},
25+
{
26+
"@type": "type.googleapis.com/google.rpc.BadRequest",
27+
"fieldViolations": [
28+
{
29+
"field": "language_code",
30+
"description": "Field is required"
31+
}
32+
]
33+
},
34+
{
35+
"@type": "type.googleapis.com/google.chrome.policy.v1.PolicyModificationErrorDetails",
36+
"modificationErrors": [
37+
{
38+
"policyTargetKey": {
39+
"targetResource": "orgunits/03ph8a2z19ryqq8"
40+
},
41+
"policySchema": "chrome.users.BrowserThemeColor",
42+
"fieldErrors": [
43+
{
44+
"field": "browserThemeColor",
45+
"error": "Field is an invalid hex color. Only the numbers 0-9 and letters A-F are permitted."
46+
}
47+
]
48+
}
49+
]
50+
},
51+
{
52+
"@type": "type.googleapis.com/google.mybusiness.v4.ValidationError",
53+
"errorDetails": [
54+
{
55+
"code": 3,
56+
"field": "regular_hours.periods.close_time",
57+
"message": "Time field must follow hh:mm format.",
58+
"value": "25:00"
59+
}
60+
]
61+
}
62+
]
63+
}
64+
}
65+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"code": 400,
3+
"message": "The template parameters are invalid.",
4+
"status": "INVALID_ARGUMENT",
5+
"details": [
6+
{
7+
"@type": "type.googleapis.com/google.dataflow.v1beta3.InvalidTemplateParameters",
8+
"reason": "TEST REASON 1",
9+
"parameterViolations": [
10+
{
11+
"parameter": "safeBrowsingApiKey",
12+
"description": "Parameter didn't match regex '^[0-9a-zA-Z_]+$'"
13+
}
14+
]
15+
},
16+
{
17+
"@type": "type.googleapis.com/google.rpc.DebugInfo",
18+
"detail": "test detail"
19+
},
20+
{
21+
"@type": "type.googleapis.com/google.rpc.DebugInfo",
22+
"reason": "test reason 2"
23+
},
24+
{
25+
"@type": "type.googleapis.com/google.rpc.BadRequest",
26+
"fieldViolations": [
27+
{
28+
"field": "language_code",
29+
"description": "Field is required"
30+
}
31+
]
32+
},
33+
{
34+
"@type": "type.googleapis.com/google.chrome.policy.v1.PolicyModificationErrorDetails",
35+
"modificationErrors": [
36+
{
37+
"policyTargetKey": {
38+
"targetResource": "orgunits/03ph8a2z19ryqq8"
39+
},
40+
"policySchema": "chrome.users.BrowserThemeColor",
41+
"fieldErrors": [
42+
{
43+
"field": "browserThemeColor",
44+
"error": "Field is an invalid hex color. Only the numbers 0-9 and letters A-F are permitted."
45+
}
46+
]
47+
}
48+
]
49+
},
50+
{
51+
"@type": "type.googleapis.com/google.mybusiness.v4.ValidationError",
52+
"errorDetails": [
53+
{
54+
"code": 3,
55+
"field": "regular_hours.periods.close_time",
56+
"message": "Time field must follow hh:mm format.",
57+
"value": "25:00"
58+
}
59+
]
60+
}
61+
]
62+
}
63+

0 commit comments

Comments
 (0)