com.google.rpc.Status.getCode()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(174)

本文整理了Java中com.google.rpc.Status.getCode()方法的一些代码示例,展示了Status.getCode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Status.getCode()方法的具体详情如下:
包路径:com.google.rpc.Status
类名称:Status
方法名:getCode

Status.getCode介绍

[英]```
The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].

`int32 code = 1;`
[中]```
The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].

int32 code = 1;

代码示例

代码示例来源:origin: googleapis/google-cloud-java

/**
  * Returns the error code corresponding to the given status, or {@code UNKNOWN} if not recognized.
  */
 static ErrorCode fromRpcStatus(com.google.rpc.Status status) {
  ErrorCode code = errorByRpcCode.get(status.getCode());
  return code == null ? UNKNOWN : code;
 }
}

代码示例来源:origin: googleapis/google-cloud-java

/** Convert an entry's status from a protobuf to an {@link ApiException}. */
private ApiException createEntryError(com.google.rpc.Status protoStatus) {
 io.grpc.Status grpcStatus =
   io.grpc.Status.fromCodeValue(protoStatus.getCode())
     .withDescription(protoStatus.getMessage());
 StatusCode gaxStatusCode = GrpcStatusCode.of(grpcStatus.getCode());
 return ApiExceptionFactory.createException(
   grpcStatus.asRuntimeException(),
   gaxStatusCode,
   retryableCodes.contains(gaxStatusCode.getCode()));
}

代码示例来源:origin: googleapis/google-cloud-java

if (entry.getStatus().getCode() == Code.OK_VALUE) {
 continue;

代码示例来源:origin: googleapis/google-cloud-java

Status status =
  change.hasCause()
    ? Status.fromCodeValue(change.getCause().getCode())
    : Status.CANCELLED;
closeStream(

代码示例来源:origin: com.google.cloud/google-cloud-spanner

/**
  * Returns the error code corresponding to the given status, or {@code UNKNOWN} if not recognized.
  */
 static ErrorCode fromRpcStatus(com.google.rpc.Status status) {
  ErrorCode code = errorByRpcCode.get(status.getCode());
  return code == null ? UNKNOWN : code;
 }
}

代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client

private static Code getGrpcCode(Status status) {
 return status == null ? null : io.grpc.Status.fromCodeValue(status.getCode()).getCode();
}

代码示例来源:origin: com.xorlev.grpc-jersey/jersey-rpc-support

@java.lang.Override
public boolean equals(final java.lang.Object obj) {
 if (obj == this) {
  return true;
 }
 if (!(obj instanceof com.google.rpc.Status)) {
  return super.equals(obj);
 }
 com.google.rpc.Status other = (com.google.rpc.Status) obj;
 boolean result = true;
 result = result && (getCode()
   == other.getCode());
 result = result && getMessage()
   .equals(other.getMessage());
 result = result && getDetailsList()
   .equals(other.getDetailsList());
 result = result && unknownFields.equals(other.unknownFields);
 return result;
}

代码示例来源:origin: envoyproxy/java-control-plane

@java.lang.Override
public boolean equals(final java.lang.Object obj) {
 if (obj == this) {
  return true;
 }
 if (!(obj instanceof com.google.rpc.Status)) {
  return super.equals(obj);
 }
 com.google.rpc.Status other = (com.google.rpc.Status) obj;
 boolean result = true;
 result = result && (getCode()
   == other.getCode());
 result = result && getMessage()
   .equals(other.getMessage());
 result = result && getDetailsList()
   .equals(other.getDetailsList());
 result = result && unknownFields.equals(other.unknownFields);
 return result;
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

@java.lang.Override
public boolean equals(final java.lang.Object obj) {
 if (obj == this) {
  return true;
 }
 if (!(obj instanceof com.google.rpc.Status)) {
  return super.equals(obj);
 }
 com.google.rpc.Status other = (com.google.rpc.Status) obj;
 boolean result = true;
 result = result && (getCode()
   == other.getCode());
 result = result && getMessage()
   .equals(other.getMessage());
 result = result && getDetailsList()
   .equals(other.getDetailsList());
 return result;
}

代码示例来源:origin: envoyproxy/java-control-plane

@java.lang.Override
public int hashCode() {
 if (memoizedHashCode != 0) {
  return memoizedHashCode;
 }
 int hash = 41;
 hash = (19 * hash) + getDescriptor().hashCode();
 hash = (37 * hash) + CODE_FIELD_NUMBER;
 hash = (53 * hash) + getCode();
 hash = (37 * hash) + MESSAGE_FIELD_NUMBER;
 hash = (53 * hash) + getMessage().hashCode();
 if (getDetailsCount() > 0) {
  hash = (37 * hash) + DETAILS_FIELD_NUMBER;
  hash = (53 * hash) + getDetailsList().hashCode();
 }
 hash = (29 * hash) + unknownFields.hashCode();
 memoizedHashCode = hash;
 return hash;
}

代码示例来源:origin: com.xorlev.grpc-jersey/jersey-rpc-support

@java.lang.Override
public int hashCode() {
 if (memoizedHashCode != 0) {
  return memoizedHashCode;
 }
 int hash = 41;
 hash = (19 * hash) + getDescriptor().hashCode();
 hash = (37 * hash) + CODE_FIELD_NUMBER;
 hash = (53 * hash) + getCode();
 hash = (37 * hash) + MESSAGE_FIELD_NUMBER;
 hash = (53 * hash) + getMessage().hashCode();
 if (getDetailsCount() > 0) {
  hash = (37 * hash) + DETAILS_FIELD_NUMBER;
  hash = (53 * hash) + getDetailsList().hashCode();
 }
 hash = (29 * hash) + unknownFields.hashCode();
 memoizedHashCode = hash;
 return hash;
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

private static Status toStatus(com.google.rpc.Status statusProto) {
 Status status = Status.fromCodeValue(statusProto.getCode());
 checkArgument(status.getCode().value() == statusProto.getCode(), "invalid status code");
 return status.withDescription(statusProto.getMessage());
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

@java.lang.Override
public int hashCode() {
 if (memoizedHashCode != 0) {
  return memoizedHashCode;
 }
 int hash = 41;
 hash = (19 * hash) + getDescriptor().hashCode();
 hash = (37 * hash) + CODE_FIELD_NUMBER;
 hash = (53 * hash) + getCode();
 hash = (37 * hash) + MESSAGE_FIELD_NUMBER;
 hash = (53 * hash) + getMessage().hashCode();
 if (getDetailsCount() > 0) {
  hash = (37 * hash) + DETAILS_FIELD_NUMBER;
  hash = (53 * hash) + getDetailsList().hashCode();
 }
 hash = (29 * hash) + unknownFields.hashCode();
 memoizedHashCode = hash;
 return hash;
}

代码示例来源:origin: com.google.api/gax-grpc

@Override
public StatusCode getErrorCode() {
 return GrpcStatusCode.of(Status.fromCodeValue(operation.getError().getCode()).getCode());
}

代码示例来源:origin: googleapis/gax-java

@Override
public StatusCode getErrorCode() {
 return GrpcStatusCode.of(Status.fromCodeValue(operation.getError().getCode()).getCode());
}

代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client

private void handleEntries(Iterable<MutateRowsResponse.Entry> entries) {
 for (MutateRowsResponse.Entry entry : entries) {
  int index = (int) entry.getIndex();
  if (index >= getRequestCount()) {
   LOG.error("Got extra status: %s", entry);
   continue;
  }
  SettableFuture<MutateRowResponse> future = futures.get(index);
  if (future == null) {
   LOG.warn("Could not find a future for index %d.", index);
   continue;
  }
  Status status = entry.getStatus();
  if (status.getCode() == io.grpc.Status.Code.OK.value()) {
   future.set(MutateRowResponse.getDefaultInstance());
  } else {
   future.setException(toException(status));
  }
 }
}

代码示例来源:origin: com.google.cloud/google-cloud-bigtable

/** Convert an entry's status from a protobuf to an {@link ApiException}. */
private ApiException createEntryError(com.google.rpc.Status protoStatus) {
 io.grpc.Status grpcStatus =
   io.grpc.Status.fromCodeValue(protoStatus.getCode())
     .withDescription(protoStatus.getMessage());
 StatusCode gaxStatusCode = GrpcStatusCode.of(grpcStatus.getCode());
 return ApiExceptionFactory.createException(
   grpcStatus.asRuntimeException(),
   gaxStatusCode,
   retryableCodes.contains(gaxStatusCode.getCode()));
}

代码示例来源:origin: spring-cloud/spring-cloud-gcp

/**
 * Extract the text out of an image and return the result as a String.
 * @param imageResource the image one wishes to analyze
 * @return the text extracted from the image aggregated to a String
 * @throws CloudVisionException if the image could not be read or if text extraction failed
 */
public String extractTextFromImage(Resource imageResource) {
  AnnotateImageResponse response = analyzeImage(imageResource, Type.TEXT_DETECTION);
  String result = response.getFullTextAnnotation().getText();
  if (result.isEmpty() && response.getError().getCode() != Code.OK.getNumber()) {
    throw new CloudVisionException(response.getError().getMessage());
  }
  return result;
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-gcp-vision

/**
 * Extract the text out of an image and return the result as a String.
 * @param imageResource the image one wishes to analyze
 * @return the text extracted from the image aggregated to a String
 * @throws CloudVisionTemplate if the image could not be read or if text extraction failed
 */
public String extractTextFromImage(Resource imageResource) {
  AnnotateImageResponse response = analyzeImage(imageResource, Type.TEXT_DETECTION);
  String result = response.getFullTextAnnotation().getText();
  if (result.isEmpty() && response.getError().getCode() != Code.OK.getNumber()) {
    throw new CloudVisionException(response.getError().getMessage());
  }
  return result;
}

代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client

private static StatusRuntimeException toException(Status status) {
 io.grpc.Status grpcStatus = io.grpc.Status
   .fromCodeValue(status.getCode())
   .withDescription(status.getMessage());
 for (Any detail : status.getDetailsList()) {
  grpcStatus = grpcStatus.augmentDescription(detail.toString());
 }
 return grpcStatus.asRuntimeException();
}

相关文章