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

feat: Error Details Improvement #1929

Merged
Expand Up @@ -16,6 +16,8 @@

package com.google.cloud.spanner;

import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.ErrorDetails;
import com.google.cloud.grpc.BaseGrpcServiceException;
import com.google.common.base.Preconditions;
import com.google.protobuf.util.Durations;
Expand All @@ -24,6 +26,7 @@
import io.grpc.Metadata;
import io.grpc.Status;
import io.grpc.protobuf.ProtoUtils;
import java.util.Map;
import javax.annotation.Nullable;

/** Base exception type for all exceptions produced by the Cloud Spanner service. */
Expand Down Expand Up @@ -95,4 +98,32 @@ static long extractRetryDelay(Throwable cause) {
}
return -1L;
}

public String getReason() {
gauravpurohit06 marked this conversation as resolved.
Show resolved Hide resolved
if (this.getCause() instanceof ApiException) {
return ((ApiException) this.getCause()).getReason();
}
return null;
}

public String getDomain() {
if (this.getCause() instanceof ApiException) {
return ((ApiException) this.getCause()).getDomain();
}
return null;
}

public Map<String, String> getMetadata() {
if (this.getCause() instanceof ApiException) {
return ((ApiException) this.getCause()).getMetadata();
}
return null;
}

public ErrorDetails getErrorDetails() {
if (this.getCause() instanceof ApiException) {
return ((ApiException) this.getCause()).getErrorDetails();
}
return null;
}
}
Expand Up @@ -295,12 +295,8 @@ private static SpannerException fromApiException(ApiException exception) {
code = Status.Code.UNKNOWN;
}
ErrorCode errorCode = ErrorCode.fromGrpcStatus(Status.fromCode(code));
if (exception.getCause() != null) {
return SpannerExceptionFactory.newSpannerException(
errorCode, exception.getMessage(), exception.getCause());
} else {
return SpannerExceptionFactory.newSpannerException(errorCode, exception.getMessage());
}
return SpannerExceptionFactory.newSpannerException(
gauravpurohit06 marked this conversation as resolved.
Show resolved Hide resolved
errorCode, exception.getMessage(), exception);
}

private static boolean isRetryable(ErrorCode code, @Nullable Throwable cause) {
Expand Down