io.grpc.Status.augmentDescription()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(136)

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

Status.augmentDescription介绍

[英]Create a derived instance of Status augmenting the current description with additional detail. Leading and trailing whitespace may be removed; this may change in the future.
[中]创建状态的派生实例,并使用其他详细信息扩充当前描述。可以删除前导和尾随空格;这在未来可能会改变。

代码示例

代码示例来源:origin: zeebe-io/zeebe

public GrpcStatusExceptionImpl(String message, Status status, Throwable cause) {
 super(message, cause);
 this.status = status.augmentDescription(message);
}

代码示例来源:origin: io.grpc/grpc-grpclb

@Override
 public void run() {
  handleStreamClosed(Status.fromThrowable(error)
    .augmentDescription("Stream to GRPCLB LoadBalancer had an error"));
 }
});

代码示例来源:origin: zeebe-io/zeebe

@Override
 public Status getGrpcStatus() {
  return Status.INVALID_ARGUMENT.augmentDescription(getMessage());
 }
}

代码示例来源:origin: io.grpc/grpc-core

Http2Error(int code, Status status) {
 this.code = code;
 this.status = status.augmentDescription("HTTP/2 error code: " + this.name());
}

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

Http2Error(int code, Status status) {
 this.code = code;
 this.status = status.augmentDescription("HTTP/2 error code: " + this.name());
}

代码示例来源:origin: zeebe-io/zeebe

private Status mapBrokerErrorToStatus(BrokerError error) {
 switch (error.getCode()) {
  case WORKFLOW_NOT_FOUND:
   return Status.NOT_FOUND.augmentDescription(error.getMessage());
  default:
   return Status.INTERNAL.augmentDescription(
     String.format(
       "Unexpected error occurred between gateway and broker (code: %s)",
       error.getCode()));
 }
}

代码示例来源:origin: zeebe-io/zeebe

private Status mapRejectionToStatus(BrokerRejection rejection) {
  final String description =
    String.format(
      "Command rejected with code '%s': %s", rejection.getIntent(), rejection.getReason());
  final Status status;

  switch (rejection.getType()) {
   case INVALID_ARGUMENT:
    status = Status.INVALID_ARGUMENT;
    break;
   case NOT_FOUND:
    status = Status.NOT_FOUND;
    break;
   case ALREADY_EXISTS:
    status = Status.ALREADY_EXISTS;
    break;
   case INVALID_STATE:
    status = Status.FAILED_PRECONDITION;
    break;
   default:
    status = Status.UNKNOWN;
    break;
  }

  return status.augmentDescription(description);
 }
}

代码示例来源:origin: saturnism/grpc-java-by-example

@Override
public void customException(EchoRequest request, StreamObserver<EchoResponse> responseObserver) {
 try {
  throw new CustomException("Custom exception!");
 } catch (Exception e) {
  responseObserver.onError(Status.INTERNAL
    .withDescription(e.getMessage())
    .augmentDescription("customException()")
    .withCause(e) // This can be attached to the Status locally, but NOT transmitted to the client!
    .asRuntimeException());
 }
}

代码示例来源:origin: zeebe-io/zeebe

private StatusRuntimeException convertThrowable(Throwable cause) {
 Status status = Status.INTERNAL;
 if (cause instanceof ExecutionException) {
  return convertThrowable(cause.getCause());
 }
 if (cause instanceof BrokerErrorException) {
  status = mapBrokerErrorToStatus(((BrokerErrorException) cause).getError());
 } else if (cause instanceof BrokerRejectionException) {
  status = mapRejectionToStatus(((BrokerRejectionException) cause).getRejection());
 } else if (cause instanceof ClientOutOfMemoryException) {
  status = Status.UNAVAILABLE.augmentDescription(cause.getMessage());
 } else if (cause instanceof GrpcStatusException) {
  status = ((GrpcStatusException) cause).getGrpcStatus();
 } else {
  status = status.augmentDescription("Unexpected error occurred during the request processing");
 }
 final StatusRuntimeException convertedThrowable = status.withCause(cause).asRuntimeException();
 Loggers.GATEWAY_LOGGER.error("Error handling gRPC request", convertedThrowable);
 return convertedThrowable;
}

代码示例来源:origin: io.grpc/grpc-core

/**
 * Called by subclasses for the terminal trailer metadata on a stream.
 *
 * @param trailers the received terminal trailer metadata
 */
protected void transportTrailersReceived(Metadata trailers) {
 Preconditions.checkNotNull(trailers, "trailers");
 if (transportError == null && !headersReceived) {
  transportError = validateInitialMetadata(trailers);
  if (transportError != null) {
   transportErrorMetadata = trailers;
  }
 }
 if (transportError != null) {
  transportError = transportError.augmentDescription("trailers: " + trailers);
  http2ProcessingFailed(transportError, false, transportErrorMetadata);
 } else {
  Status status = statusFromTrailers(trailers);
  stripTransportDetails(trailers);
  inboundTrailersReceived(trailers, status);
 }
}

代码示例来源:origin: io.grpc/grpc-core

/**
 * Inspect initial headers to make sure they conform to HTTP and gRPC, returning a {@code Status}
 * on failure.
 *
 * @return status with description of failure, or {@code null} when valid
 */
@Nullable
private Status validateInitialMetadata(Metadata headers) {
 Integer httpStatus = headers.get(HTTP2_STATUS);
 if (httpStatus == null) {
  return Status.INTERNAL.withDescription("Missing HTTP status code");
 }
 String contentType = headers.get(GrpcUtil.CONTENT_TYPE_KEY);
 if (!GrpcUtil.isGrpcContentType(contentType)) {
  return GrpcUtil.httpStatusToGrpcStatus(httpStatus)
    .augmentDescription("invalid content-type: " + contentType);
 }
 return null;
}

代码示例来源:origin: io.grpc/grpc-core

if (transportError != null) {
 transportError = transportError.augmentDescription("headers: " + headers);
 return;
  transportError = transportError.augmentDescription("headers: " + headers);
  transportErrorMetadata = headers;
  errorCharset = extractCharset(headers);

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

/**
 * Inspect initial headers to make sure they conform to HTTP and gRPC, returning a {@code Status}
 * on failure.
 *
 * @return status with description of failure, or {@code null} when valid
 */
@Nullable
private Status validateInitialMetadata(Metadata headers) {
 Integer httpStatus = headers.get(HTTP2_STATUS);
 if (httpStatus == null) {
  return Status.INTERNAL.withDescription("Missing HTTP status code");
 }
 String contentType = headers.get(GrpcUtil.CONTENT_TYPE_KEY);
 if (!GrpcUtil.isGrpcContentType(contentType)) {
  return GrpcUtil.httpStatusToGrpcStatus(httpStatus)
    .augmentDescription("invalid content-type: " + contentType);
 }
 return null;
}

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

if (transportError != null) {
 transportError = transportError.augmentDescription("headers: " + headers);
 return;
  transportError = transportError.augmentDescription("headers: " + headers);
  transportErrorMetadata = headers;
  errorCharset = extractCharset(headers);

代码示例来源: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();
}

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

/**
 * Called by subclasses for the terminal trailer metadata on a stream.
 *
 * @param trailers the received terminal trailer metadata
 */
protected void transportTrailersReceived(Metadata trailers) {
 Preconditions.checkNotNull(trailers, "trailers");
 if (transportError == null && !headersReceived) {
  transportError = validateInitialMetadata(trailers);
  if (transportError != null) {
   transportErrorMetadata = trailers;
  }
 }
 if (transportError != null) {
  transportError = transportError.augmentDescription("trailers: " + trailers);
  http2ProcessingFailed(transportError, false, transportErrorMetadata);
 } else {
  Status status = statusFromTrailers(trailers);
  stripTransportDetails(trailers);
  inboundTrailersReceived(trailers, status);
 }
}

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

/**
 * Extract the response status from trailers.
 */
private Status statusFromTrailers(Metadata trailers) {
 Status status = trailers.get(InternalStatus.CODE_KEY);
 if (status != null) {
  return status.withDescription(trailers.get(InternalStatus.MESSAGE_KEY));
 }
 // No status; something is broken. Try to provide a resonanable error.
 if (headersReceived) {
  return Status.UNKNOWN.withDescription("missing GRPC status in response");
 }
 Integer httpStatus = trailers.get(HTTP2_STATUS);
 if (httpStatus != null) {
  status = GrpcUtil.httpStatusToGrpcStatus(httpStatus);
 } else {
  status = Status.INTERNAL.withDescription("missing HTTP status code");
 }
 return status.augmentDescription(
   "missing GRPC status, inferred error from HTTP status code");
}

代码示例来源:origin: io.grpc/grpc-core

/**
 * Extract the response status from trailers.
 */
private Status statusFromTrailers(Metadata trailers) {
 Status status = trailers.get(InternalStatus.CODE_KEY);
 if (status != null) {
  return status.withDescription(trailers.get(InternalStatus.MESSAGE_KEY));
 }
 // No status; something is broken. Try to provide a resonanable error.
 if (headersReceived) {
  return Status.UNKNOWN.withDescription("missing GRPC status in response");
 }
 Integer httpStatus = trailers.get(HTTP2_STATUS);
 if (httpStatus != null) {
  status = GrpcUtil.httpStatusToGrpcStatus(httpStatus);
 } else {
  status = Status.INTERNAL.withDescription("missing HTTP status code");
 }
 return status.augmentDescription(
   "missing GRPC status, inferred error from HTTP status code");
}

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

transportError = transportError.augmentDescription("DATA-----------------------------\n"
  + ReadableBuffers.readAsString(frame, errorCharset));
frame.close();

代码示例来源:origin: io.grpc/grpc-core

transportError = transportError.augmentDescription("DATA-----------------------------\n"
  + ReadableBuffers.readAsString(frame, errorCharset));
frame.close();

相关文章