use of com.tencent.polaris.api.exception.ErrorCode in project polaris-java by polarismesh.
the class SpecStreamClient method validMessage.
/**
* 检查该应答是否合法,不合法则走异常流程
*
* @param response 服务端应答
* @return 合法返回true,否则返回false
*/
private ValidResult validMessage(ResponseProto.DiscoverResponse response) {
ErrorCode errorCode = ErrorCode.Success;
if (response.hasCode()) {
errorCode = ServerCodes.convertServerErrorToRpcError(response.getCode().getValue());
}
ServiceProto.Service service;
if (CollectionUtils.isNotEmpty(response.getServicesList())) {
service = response.getServicesList().get(0);
} else {
service = response.getService();
}
if (null == service || StringUtils.isEmpty(service.getNamespace().getValue()) || StringUtils.isEmpty(service.getName().getValue())) {
return new ValidResult(null, ErrorCode.INVALID_SERVER_RESPONSE, "service is empty, response text is " + response.toString());
}
EventType eventType = GrpcUtil.buildEventType(response.getType());
if (eventType == EventType.UNKNOWN) {
return new ValidResult(null, ErrorCode.INVALID_SERVER_RESPONSE, "invalid event type " + response.getType());
}
ServiceEventKey serviceEventKey = new ServiceEventKey(new ServiceKey(service.getNamespace().getValue(), service.getName().getValue()), eventType);
if (errorCode == ErrorCode.SERVER_ERROR) {
// 返回了500错误
return new ValidResult(serviceEventKey, errorCode, "invalid event type " + response.getType());
}
return new ValidResult(serviceEventKey, ErrorCode.Success, "");
}
Aggregations