Skip to content

Commit d3cd69d

Browse files
committed
fix: handle request body and unknown error
1 parent bfcad8b commit d3cd69d

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

gax-java/gax/src/main/java/com/google/api/gax/tracing/ErrorTypeUtil.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ public String toString() {
8888
* <li>{@code CLIENT_REDIRECT_ERROR}: Problem handling HTTP redirects.
8989
* <li>{@code CLIENT_AUTHENTICATION_ERROR}: Error during credential acquisition or
9090
* application.
91-
* <li>{@code CLIENT_UNKNOWN_ERROR}: Other unclassified client-side network or protocol
92-
* errors.
9391
* </ul>
9492
* <li><b>Language-specific error type:</b> The class or struct name of the exception or error
9593
* if available. This must be low-cardinality, meaning it returns the short name of the
@@ -174,13 +172,12 @@ private static String getClientSideError(Throwable error) {
174172
if (error instanceof IllegalArgumentException) { // This covers CLIENT_REQUEST_ERROR
175173
return ErrorType.CLIENT_REQUEST_ERROR.toString();
176174
}
177-
if (error.getClass().getSimpleName().contains("RequestBodyException")) {
175+
if (isRequestBodyError(error)) {
178176
return ErrorType.CLIENT_REQUEST_BODY_ERROR.toString();
179177
}
180-
if (error.getClass().getSimpleName().contains("UnknownClientException")) {
178+
if (isClientUnknownError(error)) {
181179
return ErrorType.CLIENT_UNKNOWN_ERROR.toString();
182180
}
183-
184181
return null;
185182
}
186183

@@ -208,4 +205,12 @@ private static boolean isClientRedirectError(Throwable e) {
208205
private static boolean isClientAuthenticationError(Throwable e) {
209206
return e.getClass().getName().contains("GoogleAuthException");
210207
}
208+
209+
private static boolean isRequestBodyError(Throwable e) {
210+
return e.getClass().getName().contains("RestSerializationException");
211+
}
212+
213+
private static boolean isClientUnknownError(Throwable e) {
214+
return e.getClass().getName().toLowerCase().contains("unknown");
215+
}
211216
}

gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void testAttemptFailed_clientRequestBodyError() {
261261

262262
tracer.attemptStarted(new Object(), 1);
263263

264-
tracer.attemptFailedRetriesExhausted(new RequestBodyException());
264+
tracer.attemptFailedRetriesExhausted(new TestRestSerializationException());
265265

266266
verify(attemptHandle)
267267
.addAttribute(
@@ -338,7 +338,7 @@ public RedirectException(String message) {
338338
}
339339
}
340340

341-
private static class RequestBodyException extends RuntimeException {}
341+
private static class TestRestSerializationException extends RuntimeException {}
342342

343343
private static class UnknownClientException extends RuntimeException {}
344344
}

0 commit comments

Comments
 (0)