Utils { public static Status statusFromThrowable(Throwable t) { Status s = Status.fromThrowable(t); if (s.getCode() != Status.Code.UNKNOWN) { return s; } if (false && t instanceof ClosedChannelException) { return Status.UNKNOWN.withCause(t); } if (t instanceof IOException) { return Status.UNAVAILABLE.withCause(t); } if (t instanceof Http2Exception) { return Status.INTERNAL.withCause(t); } return s; } private  Utils(); static Metadata convertHeaders(Http2Headers http2Headers); static Http2Headers convertClientHeaders(Metadata headers,
      AsciiString scheme,
      AsciiString defaultPath,
      AsciiString authority); static Http2Headers convertServerHeaders(Metadata headers); static Metadata convertTrailers(Http2Headers http2Headers); static Http2Headers convertTrailers(Metadata trailers, boolean headersSent); static Status statusFromThrowable(Throwable t); static final AsciiString STATUS_OK; static final AsciiString HTTP_METHOD; static final AsciiString HTTPS; static final AsciiString HTTP; static final AsciiString CONTENT_TYPE_HEADER; static final AsciiString CONTENT_TYPE_GRPC; static final AsciiString TE_HEADER; static final AsciiString TE_TRAILERS; static final AsciiString USER_AGENT; static final Resource<EventLoopGroup> DEFAULT_BOSS_EVENT_LOOP_GROUP; static final Resource<EventLoopGroup> DEFAULT_WORKER_EVENT_LOOP_GROUP; static final AttributeKey<SSLSession> SSL_SESSION_ATTR_KEY; }
@Test public void testStatusFromThrowable() { Status s = Status.CANCELLED.withDescription("msg"); assertSame(s, Utils.statusFromThrowable(new Exception(s.asException()))); Throwable t; t = new ConnectTimeoutException("msg"); assertStatusEquals(Status.UNAVAILABLE.withCause(t), Utils.statusFromThrowable(t)); t = new Http2Exception(Http2Error.INTERNAL_ERROR, "msg"); assertStatusEquals(Status.INTERNAL.withCause(t), Utils.statusFromThrowable(t)); t = new Exception("msg"); assertStatusEquals(Status.UNKNOWN.withCause(t), Utils.statusFromThrowable(t)); }