コード例 #1
0
ファイル: GrpcUtil.java プロジェクト: mingfly/grpc-java
 static {
   Http2Error[] errors = Http2Error.values();
   int size = (int) errors[errors.length - 1].code() + 1;
   codeMap = new Http2Error[size];
   for (Http2Error error : errors) {
     int index = (int) error.code();
     codeMap[index] = error;
   }
 }
コード例 #2
0
ファイル: GrpcUtil.java プロジェクト: mingfly/grpc-java
    /**
     * Looks up the {@link Status} from the given HTTP/2 error code. This is preferred over {@code
     * forCode(code).status()}, to more easily conform to HTTP/2:
     *
     * <blockquote>
     *
     * Unknown or unsupported error codes MUST NOT trigger any special behavior. These MAY be
     * treated by an implementation as being equivalent to INTERNAL_ERROR.
     *
     * </blockquote>
     *
     * @param code the HTTP/2 error code.
     * @return a {@link Status} representing the given error.
     */
    public static Status statusForCode(long code) {
      Http2Error error = forCode(code);
      if (error == null) {
        // This "forgets" the message of INTERNAL_ERROR while keeping the same status code.
        Status.Code statusCode = INTERNAL_ERROR.status().getCode();
        return Status.fromCodeValue(statusCode.value())
            .withDescription("Unrecognized HTTP/2 error code: " + code);
      }

      return error.status();
    }