Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add reason field to Details in GoogleJsonErrorObject #1831

Merged
merged 3 commits into from Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 1 addition & 47 deletions google-api-client-bom/pom.xml
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version='1.0' encoding='UTF-8'?>
Neenu1995 marked this conversation as resolved.
Show resolved Hide resolved
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.api-client</groupId>
Expand Down Expand Up @@ -65,52 +65,6 @@
<artifactId>google-api-client</artifactId>
<version>1.31.6-SNAPSHOT</version><!-- {x-version-update:google-api-client:current} -->
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-android</artifactId>
<version>1.31.6-SNAPSHOT</version><!-- {x-version-update:google-api-client:current} -->
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-appengine</artifactId>
<version>1.31.6-SNAPSHOT</version><!-- {x-version-update:google-api-client:current} -->
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-assembly</artifactId>
<version>1.31.6-SNAPSHOT</version><!-- {x-version-update:google-api-client:current} -->
<type>pom</type>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-gson</artifactId>
<version>1.31.6-SNAPSHOT</version><!-- {x-version-update:google-api-client:current} -->
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-jackson2</artifactId>
<version>1.31.6-SNAPSHOT</version><!-- {x-version-update:google-api-client:current} -->
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-java6</artifactId>
<version>1.31.6-SNAPSHOT</version><!-- {x-version-update:google-api-client:current} -->
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-protobuf</artifactId>
<version>1.31.6-SNAPSHOT</version><!-- {x-version-update:google-api-client:current} -->
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-servlet</artifactId>
<version>1.31.6-SNAPSHOT</version><!-- {x-version-update:google-api-client:current} -->
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-xml</artifactId>
<version>1.31.6-SNAPSHOT</version><!-- {x-version-update:google-api-client:current} -->
</dependency>
</dependencies>
</dependencyManagement>
<build>
Expand Down
4 changes: 2 additions & 2 deletions google-api-client/pom.xml
@@ -1,5 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version='1.0' encoding='UTF-8'?>
Neenu1995 marked this conversation as resolved.
Show resolved Hide resolved
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google.api-client</groupId>
Expand Down
Expand Up @@ -189,6 +189,7 @@ public static class Details {
private String type;

@Key private String detail;
@Key private String reason;
@Key private List<ParameterViolations> parameterViolations;

public String getType() {
Expand All @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is supposed to be nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

}

public List<ParameterViolations> getParameterViolations() {
return parameterViolations;
}
Expand Down
Expand Up @@ -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());
}
}
@@ -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"
}
]
}
}

5 changes: 2 additions & 3 deletions pom.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<?xml version='1.0' encoding='UTF-8'?>
Neenu1995 marked this conversation as resolved.
Show resolved Hide resolved
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-parent</artifactId>
Expand Down