From b7cb0e2c0c7e93311e7b889007743be36db0f89b Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Fri, 18 Jun 2021 16:54:45 -0400 Subject: [PATCH 1/3] fix: add reason field to Details in GoogleJsonErrorObject --- google-api-client-bom/pom.xml | 48 +------------------ google-api-client/pom.xml | 4 +- .../googleapis/json/GoogleJsonError.java | 9 ++++ .../googleapis/json/GoogleJsonErrorTest.java | 44 +++++++++++++++++ .../json/errorWithReasonInDetails.json | 31 ++++++++++++ pom.xml | 5 +- 6 files changed, 89 insertions(+), 52 deletions(-) create mode 100644 google-api-client/src/test/resources/com/google/api/client/googleapis/json/errorWithReasonInDetails.json diff --git a/google-api-client-bom/pom.xml b/google-api-client-bom/pom.xml index d7df1b656..46376ba21 100644 --- a/google-api-client-bom/pom.xml +++ b/google-api-client-bom/pom.xml @@ -1,4 +1,4 @@ - + 4.0.0 com.google.api-client @@ -65,52 +65,6 @@ google-api-client 1.31.6-SNAPSHOT - - com.google.api-client - google-api-client-android - 1.31.6-SNAPSHOT - - - com.google.api-client - google-api-client-appengine - 1.31.6-SNAPSHOT - - - com.google.api-client - google-api-client-assembly - 1.31.6-SNAPSHOT - pom - - - com.google.api-client - google-api-client-gson - 1.31.6-SNAPSHOT - - - com.google.api-client - google-api-client-jackson2 - 1.31.6-SNAPSHOT - - - com.google.api-client - google-api-client-java6 - 1.31.6-SNAPSHOT - - - com.google.api-client - google-api-client-protobuf - 1.31.6-SNAPSHOT - - - com.google.api-client - google-api-client-servlet - 1.31.6-SNAPSHOT - - - com.google.api-client - google-api-client-xml - 1.31.6-SNAPSHOT - diff --git a/google-api-client/pom.xml b/google-api-client/pom.xml index 89c14b479..200ee2073 100644 --- a/google-api-client/pom.xml +++ b/google-api-client/pom.xml @@ -1,5 +1,5 @@ - + + 4.0.0 com.google.api-client diff --git a/google-api-client/src/main/java/com/google/api/client/googleapis/json/GoogleJsonError.java b/google-api-client/src/main/java/com/google/api/client/googleapis/json/GoogleJsonError.java index 1a530145a..246c3fd1e 100644 --- a/google-api-client/src/main/java/com/google/api/client/googleapis/json/GoogleJsonError.java +++ b/google-api-client/src/main/java/com/google/api/client/googleapis/json/GoogleJsonError.java @@ -189,6 +189,7 @@ public static class Details { private String type; @Key private String detail; + @Key private String reason; @Key private List parameterViolations; public String getType() { @@ -207,6 +208,14 @@ public void setDetail(String detail) { this.detail = detail; } + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + public List getParameterViolations() { return parameterViolations; } diff --git a/google-api-client/src/test/java/com/google/api/client/googleapis/json/GoogleJsonErrorTest.java b/google-api-client/src/test/java/com/google/api/client/googleapis/json/GoogleJsonErrorTest.java index 99cc3b1d1..c988804a6 100644 --- a/google-api-client/src/test/java/com/google/api/client/googleapis/json/GoogleJsonErrorTest.java +++ b/google-api-client/src/test/java/com/google/api/client/googleapis/json/GoogleJsonErrorTest.java @@ -125,4 +125,48 @@ public void testParse_withDetails() throws Exception { assertEquals(DETAILS_ERROR, FACTORY.toString(errorResponse)); assertNotNull(errorResponse.getDetails()); } + + public void testParse_withReasonInDetails() throws Exception { + String DETAILS_ERROR = + "{" + + "\"code\":400," + + "\"details\":" + + "[{" + + "\"@type\":\"type.googleapis.com/google.dataflow.v1beta3.InvalidTemplateParameters\"," + + "\"parameterViolations\":[{" + + "\"description\":\"Parameter didn't match regex '^[0-9a-zA-Z_]+$'\"," + + "\"parameter\":\"safeBrowsingApiKey\"" + + "}]," + + "\"reason\":\"TEST REASON 1\"" + + "},{" + + "\"@type\":\"type.googleapis.com/google.rpc.DebugInfo\"," + + "\"detail\":\"test detail\"" + + "},{" + + "\"@type\":\"type.googleapis.com/google.rpc.DebugInfo\"," + + "\"reason\":\"test reason 2\"" + + "},{" + + "\"@type\":\"type.googleapis.com/google.rpc.DebugInfo\"" + + "}]," + + "\"message\":\"The template parameters are invalid.\"," + + "\"status\":\"INVALID_ARGUMENT\"" + + "}"; + InputStream errorContent = + GoogleJsonErrorTest.class.getResourceAsStream("errorWithReasonInDetails.json"); + + HttpTransport transport = + new ErrorTransport( + new MockLowLevelHttpResponse() + .setContent(errorContent) + .setContentType(Json.MEDIA_TYPE) + .setStatusCode(HttpStatusCodes.STATUS_CODE_FORBIDDEN)); + HttpRequest request = + transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL); + request.setThrowExceptionOnExecuteError(false); + HttpResponse response = request.execute(); + com.google.api.client.googleapis.json.GoogleJsonError errorResponse = + com.google.api.client.googleapis.json.GoogleJsonError.parse(FACTORY, response); + + assertEquals(DETAILS_ERROR, FACTORY.toString(errorResponse)); + assertNotNull(errorResponse.getDetails().get(2).getReason()); + } } diff --git a/google-api-client/src/test/resources/com/google/api/client/googleapis/json/errorWithReasonInDetails.json b/google-api-client/src/test/resources/com/google/api/client/googleapis/json/errorWithReasonInDetails.json new file mode 100644 index 000000000..cd1b85ad5 --- /dev/null +++ b/google-api-client/src/test/resources/com/google/api/client/googleapis/json/errorWithReasonInDetails.json @@ -0,0 +1,31 @@ +{ + "error": { + "code": 400, + "message": "The template parameters are invalid.", + "status": "INVALID_ARGUMENT", + "details": [ + { + "@type": "type.googleapis.com/google.dataflow.v1beta3.InvalidTemplateParameters", + "reason": "TEST REASON 1", + "parameterViolations": [ + { + "parameter": "safeBrowsingApiKey", + "description": "Parameter didn't match regex '^[0-9a-zA-Z_]+$'" + } + ] + }, + { + "@type": "type.googleapis.com/google.rpc.DebugInfo", + "detail": "test detail" + }, + { + "@type": "type.googleapis.com/google.rpc.DebugInfo", + "reason": "test reason 2" + }, + { + "@type": "type.googleapis.com/google.rpc.DebugInfo" + } + ] + } +} + diff --git a/pom.xml b/pom.xml index ebc61ac00..6bad9d11c 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,5 @@ - - + + 4.0.0 com.google.api-client google-api-client-parent From fe2d4f24cf62857d4c42eaca16eaf2876db8b984 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Tue, 22 Jun 2021 10:30:27 -0400 Subject: [PATCH 2/3] chore: revert changes to pom files --- google-api-client-bom/pom.xml | 50 +++++++++++++++++++++++++++++++++-- google-api-client/pom.xml | 6 ++--- pom.xml | 11 ++++---- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/google-api-client-bom/pom.xml b/google-api-client-bom/pom.xml index 46376ba21..c45b69f35 100644 --- a/google-api-client-bom/pom.xml +++ b/google-api-client-bom/pom.xml @@ -1,4 +1,4 @@ - + 4.0.0 com.google.api-client @@ -65,6 +65,52 @@ google-api-client 1.31.6-SNAPSHOT + + com.google.api-client + google-api-client-android + 1.31.6-SNAPSHOT + + + com.google.api-client + google-api-client-appengine + 1.31.6-SNAPSHOT + + + com.google.api-client + google-api-client-assembly + 1.31.6-SNAPSHOT + pom + + + com.google.api-client + google-api-client-gson + 1.31.6-SNAPSHOT + + + com.google.api-client + google-api-client-jackson2 + 1.31.6-SNAPSHOT + + + com.google.api-client + google-api-client-java6 + 1.31.6-SNAPSHOT + + + com.google.api-client + google-api-client-protobuf + 1.31.6-SNAPSHOT + + + com.google.api-client + google-api-client-servlet + 1.31.6-SNAPSHOT + + + com.google.api-client + google-api-client-xml + 1.31.6-SNAPSHOT + @@ -150,4 +196,4 @@ - + \ No newline at end of file diff --git a/google-api-client/pom.xml b/google-api-client/pom.xml index 200ee2073..ac1a2ae25 100644 --- a/google-api-client/pom.xml +++ b/google-api-client/pom.xml @@ -1,5 +1,5 @@ - - + 4.0.0 com.google.api-client @@ -162,4 +162,4 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6bad9d11c..e4eaafe3f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ - - + + 4.0.0 com.google.api-client google-api-client-parent @@ -7,7 +8,7 @@ pom Parent for the Google API Client Library for Java The Google APIs Client Library for Java is a Java client library - for accessing any HTTP-based API on the web + for accessing any HTTP-based API on the web https://github.com/googleapis/google-api-java-client @@ -16,7 +17,7 @@ 2010 - + chingor @@ -676,4 +677,4 @@ - + \ No newline at end of file From cf67c2ed512083793f4a572636f3f7a28f154e75 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Tue, 22 Jun 2021 10:34:22 -0400 Subject: [PATCH 3/3] chore: fix formatting errors --- google-api-client-bom/pom.xml | 2 +- google-api-client/pom.xml | 4 ++-- pom.xml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/google-api-client-bom/pom.xml b/google-api-client-bom/pom.xml index c45b69f35..d7df1b656 100644 --- a/google-api-client-bom/pom.xml +++ b/google-api-client-bom/pom.xml @@ -196,4 +196,4 @@ - \ No newline at end of file + diff --git a/google-api-client/pom.xml b/google-api-client/pom.xml index ac1a2ae25..89c14b479 100644 --- a/google-api-client/pom.xml +++ b/google-api-client/pom.xml @@ -1,5 +1,5 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.google.api-client @@ -162,4 +162,4 @@ - \ No newline at end of file + diff --git a/pom.xml b/pom.xml index e4eaafe3f..5e1201517 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 com.google.api-client google-api-client-parent @@ -677,4 +677,4 @@ - \ No newline at end of file +