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 all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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());
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<packaging>pom</packaging>
<name>Parent for the Google API Client Library for Java</name>
<description>The Google APIs Client Library for Java is a Java client library
for accessing any HTTP-based API on the web</description>
for accessing any HTTP-based API on the web</description>
<url>https://github.com/googleapis/google-api-java-client</url>

<issueManagement>
Expand All @@ -17,7 +17,7 @@
</issueManagement>

<inceptionYear>2010</inceptionYear>

<developers>
<developer>
<id>chingor</id>
Expand Down