Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit 09b99d5

Browse files
authored
fix: fix gRPC code conversion (#1555)
1 parent 02436d2 commit 09b99d5

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

‎gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonExceptionCallable.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,13 @@ public void onSuccess(ResponseT r) {
9595
public void onFailure(Throwable throwable) {
9696
if (throwable instanceof HttpResponseException) {
9797
HttpResponseException e = (HttpResponseException) throwable;
98-
StatusCode.Code statusCode =
99-
HttpJsonStatusCode.httpStatusToStatusCode(e.getStatusCode(), e.getMessage());
100-
boolean canRetry = retryableCodes.contains(statusCode);
98+
StatusCode statusCode = HttpJsonStatusCode.of(e.getStatusCode(), e.getMessage());
99+
boolean canRetry = retryableCodes.contains(statusCode.getCode());
101100
String message = e.getStatusMessage();
102101
ApiException newException =
103102
message == null
104-
? ApiExceptionFactory.createException(
105-
throwable, HttpJsonStatusCode.of(statusCode), canRetry)
106-
: ApiExceptionFactory.createException(
107-
message, throwable, HttpJsonStatusCode.of(statusCode), canRetry);
103+
? ApiExceptionFactory.createException(throwable, statusCode, canRetry)
104+
: ApiExceptionFactory.createException(message, throwable, statusCode, canRetry);
108105
super.setException(newException);
109106
} else if (throwable instanceof CancellationException && cancelled) {
110107
// this just circled around, so ignore.

‎gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpJsonStatusCode.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.google.api.core.BetaApi;
3333
import com.google.api.core.InternalExtensionOnly;
3434
import com.google.api.gax.rpc.StatusCode;
35+
import com.google.api.gax.rpc.StatusCode.Code;
3536
import com.google.common.base.Strings;
3637
import java.util.Objects;
3738

@@ -46,22 +47,22 @@ public class HttpJsonStatusCode implements StatusCode {
4647
static final String UNKNOWN = "UNKNOWN";
4748

4849
private final int httpStatus;
49-
private final StatusCode.Code statusCode;
50+
private final Code statusCode;
5051

5152
/** Creates a new instance with the given status code. */
5253
public static HttpJsonStatusCode of(int httpStatus, String errorMessage) {
5354
return new HttpJsonStatusCode(httpStatus, httpStatusToStatusCode(httpStatus, errorMessage));
5455
}
5556

56-
public static HttpJsonStatusCode of(StatusCode.Code statusCode) {
57+
public static HttpJsonStatusCode of(Code statusCode) {
5758
return new HttpJsonStatusCode(statusCode.getHttpStatusCode(), statusCode);
5859
}
5960

6061
public static HttpJsonStatusCode of(com.google.rpc.Code rpcCode) {
61-
return new HttpJsonStatusCode(rpcCode.getNumber(), rpcCodeToStatusCode(rpcCode));
62+
return HttpJsonStatusCode.of(rpcCodeToStatusCode(rpcCode));
6263
}
6364

64-
static StatusCode.Code rpcCodeToStatusCode(com.google.rpc.Code rpcCode) {
65+
static Code rpcCodeToStatusCode(com.google.rpc.Code rpcCode) {
6566
switch (rpcCode) {
6667
case OK:
6768
return Code.OK;
@@ -102,7 +103,7 @@ static StatusCode.Code rpcCodeToStatusCode(com.google.rpc.Code rpcCode) {
102103
}
103104
}
104105

105-
static StatusCode.Code httpStatusToStatusCode(int httpStatus, String errorMessage) {
106+
static Code httpStatusToStatusCode(int httpStatus, String errorMessage) {
106107
String causeMessage = Strings.nullToEmpty(errorMessage).toUpperCase();
107108
switch (httpStatus) {
108109
case 200:
@@ -155,7 +156,7 @@ static StatusCode.Code httpStatusToStatusCode(int httpStatus, String errorMessag
155156
}
156157

157158
@Override
158-
public StatusCode.Code getCode() {
159+
public Code getCode() {
159160
return statusCode;
160161
}
161162

@@ -165,8 +166,8 @@ public Integer getTransportCode() {
165166
return httpStatus;
166167
}
167168

168-
private HttpJsonStatusCode(int code, StatusCode.Code statusCode) {
169-
this.httpStatus = code;
169+
private HttpJsonStatusCode(int httpStatus, Code statusCode) {
170+
this.httpStatus = httpStatus;
170171
this.statusCode = statusCode;
171172
}
172173

0 commit comments

Comments
 (0)