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

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

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

Status.fromCode介绍

[英]Return a Status given a canonical error Code object.
[中]返回给定规范错误代码对象的状态。

代码示例

代码示例来源:origin: Alluxio/alluxio

@Override
public void onNext(SaslMessage saslMessage) {
 try {
  SaslMessage response = mSaslHandshakeClientHandler.handleSaslMessage(saslMessage);
  if (response == null) {
   mRequestObserver.onCompleted();
  } else {
   mRequestObserver.onNext(response);
  }
 } catch (SaslException e) {
  mAuthenticated.setException(e);
  mRequestObserver
    .onError(Status.fromCode(Status.Code.UNAUTHENTICATED).withCause(e).asException());
 }
}

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

@Override
public synchronized void onCompleted() {
 maybeReopenStream(new StatusException(Status.fromCode(Code.UNKNOWN)));
}

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

private void destroy(Code code) throws InterruptedException {
 streamObserverCapture.getValue().onError(new StatusException(io.grpc.Status.fromCode(code)));
}

代码示例来源:origin: Alluxio/alluxio

LOG.warn("Could not serialize the cause: {}. Failed with: {}", cause, exc);
return Status.fromCode(code).asException(trailers);

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

responseObserver.onError(
   new StatusException(
     Status.fromCode(Code.ABORTED)
       .withDescription("Can only set one subscription.")));
 return;
   responseObserver.onError(
     new StatusException(
       Status.fromCode(Code.INVALID_ARGUMENT)
         .withDescription("A stream must be initialized with a ack deadline.")));
responseObserver.onError(
  new StatusException(
    Status.fromCode(Code.ABORTED)
      .withDescription(
        "The stream has not been properly initialized with a "
 responseObserver.onError(
   new StatusException(
     Status.fromCode(Code.ABORTED)
       .withDescription("Invalid modify ack deadline request.")));
 return;

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

responseObserver.onError(Status.fromCode(expectedRpc.resultCode).asRuntimeException());
return;

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

@Override
public synchronized void onCompleted() {
 maybeReopenStream(new StatusException(Status.fromCode(Code.UNKNOWN)));
}

代码示例来源:origin: gojek/feast

private StatusRuntimeException getBadRequestException(Exception e) {
  return new StatusRuntimeException(
    Status.fromCode(Status.Code.OUT_OF_RANGE).withDescription(e.getMessage()).withCause(e));
 }
}

代码示例来源:origin: gojek/feast

private StatusRuntimeException getBadRequestException(Exception e) {
  return new StatusRuntimeException(
    Status.fromCode(Status.Code.OUT_OF_RANGE).withDescription(e.getMessage()).withCause(e));
 }
}

代码示例来源:origin: gojek/feast

private StatusRuntimeException getRuntimeException(Exception e) {
 return new StatusRuntimeException(
   Status.fromCode(Status.Code.INTERNAL).withDescription(e.getMessage()).withCause(e));
}

代码示例来源:origin: gojek/feast

private StatusRuntimeException getRuntimeException(Exception e) {
 return new StatusRuntimeException(
   Status.fromCode(Status.Code.INTERNAL).withDescription(e.getMessage()).withCause(e));
}

代码示例来源:origin: gojek/feast

private void onError(StreamObserver<?> responseObserver, Code errCode, String message,
   Throwable cause) {
  responseObserver.onError(Status.fromCode(errCode)
    .withDescription(message)
    .withCause(cause)
    .asException());
 }
}

代码示例来源:origin: pravega/pravega

@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
  Context context = Context.current();
  String credentials = headers.get(Metadata.Key.of(AuthConstants.AUTHORIZATION, Metadata.ASCII_STRING_MARSHALLER));
  if (!Strings.isNullOrEmpty(credentials)) {
    String[] parts = credentials.split("\\s+", 2);
    if (parts.length == 2) {
      String method = parts[0];
      String token = parts[1];
      if (!Strings.isNullOrEmpty(method)) {
        if (method.equals(handler.getHandlerName())) {
          Principal principal;
          try {
            if ((principal = handler.authenticate(token)) == null) {
              call.close(Status.fromCode(Status.Code.UNAUTHENTICATED), headers);
              return null;
            }
          } catch (AuthException e) {
            call.close(Status.fromCode(Status.Code.UNAUTHENTICATED), headers);
            return null;
          }
          context = context.withValue(AUTH_CONTEXT_TOKEN, principal);
          context = context.withValue(INTERCEPTOR_OBJECT, this);
        }
      }
    }
  }
  // reaching this point means that the handler wasn't applicable to this request.
  return Contexts.interceptCall(context, call, headers, next);
}

代码示例来源:origin: sitewhere/sitewhere

/**
   * Convert server exception to one that can be passed back via GRPC.
   * 
   * @param t
   * @return
   */
  public static StatusException convertServerException(Throwable t) {
  StatusException thrown = null;
  if (t instanceof SiteWhereSystemException) {
    SiteWhereSystemException sysex = (SiteWhereSystemException) t;
    Status status = Status.fromCode(Code.FAILED_PRECONDITION)
      .withDescription(sysex.getCode().getCode() + ":" + sysex.getCode().getMessage());
    thrown = status.asException();
  } else if (t instanceof SiteWhereException) {
    SiteWhereException sw = (SiteWhereException) t;
    Status status = Status.fromCode(Code.FAILED_PRECONDITION)
      .withDescription(ErrorCode.Error.getCode() + ":" + sw.getMessage());
    thrown = status.asException();
  } else if (t instanceof TenantEngineNotAvailableException) {
    TenantEngineNotAvailableException sw = (TenantEngineNotAvailableException) t;
    Status status = Status.fromCode(Code.UNAVAILABLE).withDescription(sw.getMessage());
    thrown = status.asException();
  } else {
    thrown = Status.fromThrowable(t).asException();
  }
  return thrown;
  }
}

代码示例来源:origin: gojek/feast

} catch (IllegalArgumentException e) {
 responseObserver.onError(
   Status.fromCode(Code.INVALID_ARGUMENT)
     .withCause(e)
     .withDescription(e.getMessage())
 log.error("Training dataset creation failed", e);
 responseObserver.onError(
   Status.fromCode(Code.INTERNAL)
     .withCause(e)
     .withDescription("Training dataset creation failed: " + e.getMessage())

代码示例来源:origin: gojektech/feast

responseObserver.onError(
   new StatusRuntimeException(
     Status.fromCode(INTERNAL).withDescription(e.getMessage()).withCause(e)));
} finally {
 statsDClient

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void convertFromGrpcStatus() {
 // Without description
 for (io.grpc.Status.Code grpcCanonicalCode : io.grpc.Status.Code.values()) {
  io.grpc.Status grpcStatus = io.grpc.Status.fromCode(grpcCanonicalCode);
  io.opencensus.trace.Status opencensusStatus = StatusConverter.fromGrpcStatus(grpcStatus);
  assertThat(opencensusStatus.getCanonicalCode().toString())
    .isEqualTo(grpcStatus.getCode().toString());
  assertThat(opencensusStatus.getDescription()).isNull();
 }
 // With description
 for (io.grpc.Status.Code grpcCanonicalCode : io.grpc.Status.Code.values()) {
  io.grpc.Status grpcStatus =
    io.grpc.Status.fromCode(grpcCanonicalCode).withDescription("This is my description");
  io.opencensus.trace.Status opencensusStatus = StatusConverter.fromGrpcStatus(grpcStatus);
  assertThat(opencensusStatus.getCanonicalCode().toString())
    .isEqualTo(grpcStatus.getCode().toString());
  assertThat(opencensusStatus.getDescription()).isEqualTo(grpcStatus.getDescription());
 }
}

相关文章