DubboParser { @Nullable static String errorCode(Throwable error) { if (error instanceof RpcException) { int code = ((RpcException) error).getCode(); switch (code) { case RpcException.UNKNOWN_EXCEPTION: return "UNKNOWN_EXCEPTION"; case RpcException.NETWORK_EXCEPTION: return "NETWORK_EXCEPTION"; case RpcException.TIMEOUT_EXCEPTION: return "TIMEOUT_EXCEPTION"; case RpcException.BIZ_EXCEPTION: return "BIZ_EXCEPTION"; case RpcException.FORBIDDEN_EXCEPTION: return "FORBIDDEN_EXCEPTION"; case RpcException.SERIALIZATION_EXCEPTION: return "SERIALIZATION_EXCEPTION"; default: return String.valueOf(code); } } return null; }    }
@Test public void errorCodes() { assertThat(DubboParser.errorCode(null)) .isEqualTo(DubboParser.errorCode(new IOException("timeout"))) .isNull(); assertThat(DubboParser.errorCode(new RpcException(0))) .isEqualTo("UNKNOWN_EXCEPTION"); assertThat(DubboParser.errorCode(new RpcException(1))) .isEqualTo("NETWORK_EXCEPTION"); assertThat(DubboParser.errorCode(new RpcException(2))) .isEqualTo("TIMEOUT_EXCEPTION"); assertThat(DubboParser.errorCode(new RpcException(3))) .isEqualTo("BIZ_EXCEPTION"); assertThat(DubboParser.errorCode(new RpcException(4))) .isEqualTo("FORBIDDEN_EXCEPTION"); assertThat(DubboParser.errorCode(new RpcException(5))) .isEqualTo("SERIALIZATION_EXCEPTION"); assertThat(DubboParser.errorCode(new RpcException(6))) .isEqualTo("6"); }